44
55A Golang package for supporting worker supervisor model.
66The package help developer easy to run parallel tasks.
7- It's scalable with minimum effort.
7+ It's scalable with minimal effort.
88
9- easyworker package is inspired by Erlang OTP.
9+ easyworker is inspired by Erlang OTP.
1010
1111# Design
1212
@@ -19,7 +19,7 @@ The package has two main part:
1919
2020Start workers and monitor workers.
2121Send task to workers and get result(for task & stream).
22- Restart children if they're failed (depends restart strategy) .
22+ Restart(depends restart strategy) children if they're failed to call user function or panic .
2323Supervisor has one goroutine for send & manage signal to children.
2424
2525## Child
@@ -32,7 +32,7 @@ Each child has a goroutine to run its task.
3232
3333easyworker support 3 type of workers:
3434
35- * Supervisor, Start a supervisor for managing custom workers. Workers can run many type of tasks.
35+ * Supervisor, Start a supervisor for managing children. Children can run many type of tasks.
3636* Task, Add a list of task and run workers. Workers run same type of task.
3737* Stream, Start workers then push tasks to workers from channel. Workers run same type of task.
3838
@@ -63,8 +63,8 @@ Every children has a owner restart strategy.
6363
6464Currently, child has three type of restart strategy:
6565
66- * ALWAYS_RESTART, supervisor always restart children if it panic/ done.
67- * ERROR_RESTART, supervisor will restart if children was panic.
66+ * ALWAYS_RESTART, supervisor always restart children if it panic or done task .
67+ * ERROR_RESTART, supervisor will only restart if children was panic.
6868* NO_RESTART, supervisor will don't restart children for any reason.
6969
7070Children will be started after they are added to supervisor.
@@ -250,14 +250,16 @@ fnStr := func(a int, suffix string) string {
250250 return fmt.Sprintf (" %d _%s " , a, suffix)
251251}
252252
253+ num := easyworker.DefaultNumWorkers ()
254+
253255// input channel.
254- inCh := make (chan []any)
256+ inCh := make (chan []any, num )
255257
256258// result channel.
257- outCh := make (chan any)
259+ outCh := make (chan any, num )
258260
259261// number of workers = number of cpu cores (logical cores).
260- config , _ := easyworker.NewConfig (fnStr, easyworker. DefaultNumWorkers () , 3 , 1000 )
262+ config , _ := easyworker.NewConfig (fnStr, num , 3 , 1000 )
261263
262264// test with stream.
263265myStream , _ := easyworker.NewStream (config, inCh, outCh)
@@ -291,15 +293,15 @@ myStream.Stop()
291293
292294### Monitor Go
293295
294- A wrapper for goroutine for easy monitor when goroutine was panic or run task done.
296+ A wrapper for goroutine for easy to monitor when goroutine was panic or run task done.
295297
296298` Monitor ` function will return two params.
297299First param is unique reference id.
298300Second param is channel that user can receive signal.
299301
300302Signal is a struct with reference id and kind of end (failed, done).
301303
302- Go doesn't support return value, you need an other way to get if you neened .
304+ If you need get result from last run, please call ` GetResult ` .
303305
304306Example 1:
305307
0 commit comments