* Register a scheduled task handler for the provided namespace. * * See Tasks for more info about scheduled tasks and how to schedule a new one. * * @param namespace The task namespace to handle tasks from * @param cb The callback function to run, with the type of
(namespace: string, cb: (task: Tasks.Task<T>) => any)
| 199 | * ``` |
| 200 | */ |
| 201 | async onTask<T>(namespace: string, cb: (task: Tasks.Task<T>) => any) { |
| 202 | this.taskHandlers.push({ |
| 203 | name: namespace, |
| 204 | pluginId: null, |
| 205 | }); |
| 206 | |
| 207 | this.events.on("BOTLOADER_SCHEDULED_TASK_FIRED", async (evt) => { |
| 208 | if (evt.namespace === namespace && evt.pluginId == null) { |
| 209 | await cb({ |
| 210 | ...evt, |
| 211 | pluginId: evt.pluginId, |
| 212 | data: evt.data as T, |
| 213 | }); |
| 214 | } |
| 215 | }) |
| 216 | } |
| 217 | |
| 218 | createTaskBucket<T = undefined>( |
| 219 | options: { |
no test coverage detected