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
Copy file name to clipboardExpand all lines: README.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -280,13 +280,13 @@ The most relevant use-case for this library in the context of k8s controllers is
280
280
281
281
-`NewThreadManager` creates a new thread manager.
282
282
- The first argument is a `context.Context` used by the manager itself. Cancelling this context will stop the manager, and if the context contains a `logging.Logger`, the manager will use it for logging.
283
-
- The second argument is a `context.Context` that is used as a base context for the executed go routines.
284
-
- The third argument is an optional function that is executed after any go routine executed with this manager has finished. It is also possible to provide such a function for a specific go routine, instead for all of them, see below.
283
+
- The second argument is an optional function that is executed after any go routine executed with this manager has finished. It is also possible to provide such a function for a specific go routine, instead for all of them, see below.
285
284
- Use the `Run` method to start a new go routine.
285
+
- Starting a go routine cancels the context of any running go routine with the same id.
286
286
- This method also takes an optional function to be executed after the actual workload is done.
287
287
- A on-finish function specified here is executed before the on-finish function of the manager is executed.
288
288
- Note that go routines will wait for the thread manager to be started, if that has not yet happened. If the manager has been started, they will be executed immediately.
289
-
- The thread manager will cancel the context that is passed into the workload function when the manager is being stopped. If any long-running commands are being run as part of the workload, it is recommended to listen to the context's `Done` channel.
289
+
- The thread manager will cancel the context that is passed into the workload function when the manager is being stopped. If any long-running commands are being run as part of the workload, it is strongly recommended to listen to the context's `Done` channel.
290
290
- Use `Start()` to start the thread manager.
291
291
- If any go routines have been added before this is called, they will be started now. New go routines added afterwards will be started immediately.
292
292
- Calling this multiple times doesn't have any effect, unless the manager has already been stopped, in which case `Start()` will panic.
@@ -300,11 +300,11 @@ The most relevant use-case for this library in the context of k8s controllers is
300
300
#### Examples
301
301
302
302
```golang
303
-
mgr:= threads.NewThreadManager(ctx1, ctx2, nil)
303
+
mgr:= threads.NewThreadManager(ctx, nil)
304
304
mgr.Start()
305
305
// do other stuff
306
306
// start a go routine that is restarted automatically if it finishes with an error
// Run gives a new thread to run to the ThreadManager.
145
-
// id is only used for logging and debugging purposes.
146
+
// The context is used to create a new context with a cancel function for the thread.
147
+
// id is used for logging and debugging purposes.
148
+
// Note that when a thread with the same id as an already running thread is added, the running thread will be cancelled.
149
+
// If the ThreadManager has not been started yet, the previously added thread with the conflicting id will be discarded and the newly added one will be run when the ThreadManager is started instead.
150
+
// A thread MUST NOT start another thread with the same id as itself during its work function. If a thread wants to restart itself, this must happen in the onFinish function.
146
151
// work is the actual workload of the thread.
147
152
// onFinish can be used to react to the thread having finished.
148
-
// Note that there are some pre-defined functions that can be used as onFinish functions, e.g. the ThreadManager's Restart method.
0 commit comments