Call `f` in about `delayMs` milliseconds. * If this function is called multiple times before `f` runs, `f` will still only be called once. * * If `schedule` is called while `f` is running (it is asynchronous) then `f` will be called again * as soon as `f` has finished its current
()
| 62 | * See https://docs.gtk.org/glib/main-loop.html |
| 63 | */ |
| 64 | schedule() { |
| 65 | if (this.running) { |
| 66 | this.runAgain = true; |
| 67 | } else if (this.timeoutId === undefined) { |
| 68 | this.timeoutId = Async.addTimeout( |
| 69 | GLib.PRIORITY_DEFAULT, |
| 70 | this.delayMs, |
| 71 | () => { |
| 72 | // Note: need to manually catch exceptions in async functions, otherwise they will not be logged |
| 73 | this.runInternal().catch(logAsyncException); |
| 74 | return GLib.SOURCE_REMOVE; |
| 75 | } |
| 76 | ); |
| 77 | } else { |
| 78 | // Already scheduled and not running. We can just sit back and wait. |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | private async runInternal() { |
| 83 | assert( |
no test coverage detected