API / geotoolkit / util / taskscheduler / TaskScheduler
util.taskscheduler.TaskScheduler
A simple task scheduler to control parallel tasks execution
Constructors
Methods
▸ abort(): TaskScheduler
Cancel all tasks
this
▸ abortTask(id): TaskScheduler
Abort tasks by id
| Name | Type | Description |
|---|---|---|
id | number | number[] | id or array of id |
this
▸ addTask(task, options?): ITask
Add a new task to queue
Example
// add a task
scheduler.addTask((resolve, reject, cancel) => {
resolve();
});Example
// add a task and use it as a promise
scheduler.addTask((resolve, reject, cancel) => {
resolve();
}).toPromise().then((data) => {
...
}).catch((error) => {
...
});Example
// handle cancellation in the task
scheduler.addTask((resolve, reject, cancel) => {
// Handle cancellation
const AbortedErrorCode = 'Aborted';
cancel.setErrorHandler(() => {
reject(new Error(AbortedErrorCode));
});
});| Name | Type | Description |
|---|---|---|
task | Task | task function |
Optional options | TaskOptions | options all options keys are case-insensitive |
task created task
▸ getLastTaskId(): number
Return id of the last task
number
▸ getNumberOfParallelTasks(): number
Gets number of running in parallel tasks
number
count number of parallel tasks
▸ isEmpty(): boolean
Return true if there are no tasks in the queue
boolean
▸ setNumberOfParallelTasks(count): TaskScheduler
Sets number of running in parallel tasks
| Name | Type | Description |
|---|---|---|
count | number | number of parallel tasks |
this