Schedule invoke function every duration time, util close the returned bool channel. Play: https://go.dev/play/p/hbON-Xeyn5N
(duration time.Duration, fn any, args ...any)
| 165 | // Schedule invoke function every duration time, util close the returned bool channel. |
| 166 | // Play: https://go.dev/play/p/hbON-Xeyn5N |
| 167 | func Schedule(duration time.Duration, fn any, args ...any) chan bool { |
| 168 | // Catch programming error while constructing the closure |
| 169 | mustBeFunction(fn) |
| 170 | |
| 171 | quit := make(chan bool) |
| 172 | |
| 173 | go func() { |
| 174 | for { |
| 175 | unsafeInvokeFunc(fn, args...) |
| 176 | |
| 177 | select { |
| 178 | case <-time.After(duration): |
| 179 | case <-quit: |
| 180 | return |
| 181 | } |
| 182 | } |
| 183 | }() |
| 184 | |
| 185 | return quit |
| 186 | } |
| 187 | |
| 188 | // Pipeline takes a list of functions and returns a function whose param will be passed into |
| 189 | // the functions one by one. |
searching dependent graphs…