You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Feature request, or, let me know if there is an easier way to do this.
Use case: To be able to visually notify users when work is being done. I.e, when workers are being run by Textual.
Currently, there is no way to await the WorkerManager for when work is added. I would like to use this "leading edge" to trigger dom events. (I'm using a spinner) - the ability to await the "trailing edge" is available with WorkerManager.wait_for_complete
I have modified the WorkerManager and Worker classes, and the work decorator.
For this to make sense, I added the concept of a transient worker. So workers can either be transient, or long running.
Here is the new method (and modified wait_for_complete) on the WorkerManager
asyncdefwait_for_complete(self, workers: Iterable[Worker] |None=None) ->None:
"""Wait for workers to complete. Args: workers: An iterable of workers or None to wait for all workers in the manager. """awaitasyncio.gather(*[worker.wait() forworkerin (workersorself) ifworker.transient])
asyncdefwait_for_added(self) ->None:
"""Wait for a transient worker to be added. If a worker is already added, return immediately."""awaitself._worker_added.wait()
Then when the first transient worker gets added an event is set, and cleared when the last transient worker is removed.
This is what it looks like in the app demo below. The top screen is the app, where there is a spinner in the top left corner whenever there is textual work being done. The bottom screen is nettop, where you can see the actual network io from the textual workers
textual_app.mov
If this makes sense, happy to do a PR.
The text was updated successfully, but these errors were encountered:
Feature request, or, let me know if there is an easier way to do this.
Use case: To be able to visually notify users when work is being done. I.e, when workers are being run by Textual.
Currently, there is no way to await the
WorkerManager
for when work is added. I would like to use this "leading edge" to trigger dom events. (I'm using a spinner) - the ability to await the "trailing edge" is available withWorkerManager.wait_for_complete
I have modified the
WorkerManager
andWorker
classes, and thework
decorator.Here is how I'm using it in a Textual app:
For this to make sense, I added the concept of a transient worker. So workers can either be transient, or long running.
Here is the new method (and modified wait_for_complete) on the
WorkerManager
Then when the first transient worker gets added an event is set, and cleared when the last transient worker is removed.
This is what it looks like in the app demo below. The top screen is the app, where there is a spinner in the top left corner whenever there is textual work being done. The bottom screen is nettop, where you can see the actual network io from the textual workers
textual_app.mov
If this makes sense, happy to do a PR.
The text was updated successfully, but these errors were encountered: