runLoop handles registered tasks and agent close.
(onClose func())
| 46 | |
| 47 | // runLoop handles registered tasks and agent close. |
| 48 | func (l *Loop) runLoop(onClose func()) { |
| 49 | defer func() { |
| 50 | onClose() |
| 51 | close(l.taskLoopDone) |
| 52 | }() |
| 53 | |
| 54 | for { |
| 55 | select { |
| 56 | case <-l.done: |
| 57 | return |
| 58 | case t := <-l.tasks: |
| 59 | t.fn(l) |
| 60 | close(t.done) |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | // Close stops the loop after finishing the execution of the current task. |
| 66 | // Other pending tasks will not be executed. |