new TaskScheduler(threadPoolSize)
Creates a new TaskScheduler instance.
Using the SFSApi#newScheduler factory method instead of this constructor is recommended. See the method description for a usage example.
Parameters:
| Name | Type | Description |
|---|---|---|
threadPoolSize |
number | The number of threads backing the scheduler (recommended value between 1 and 4). |
Methods
-
destroy()
-
Destroys the TaskScheduler instance and all the tasks that are currently running.
-
getThreadPoolSize()
-
Returns the size of the thread pool handling the tasks.
Returns:
The number of threads backing the scheduler.- Type
- number
-
schedule(runnerFn, delay [, context])
-
Schedules a new task to be executed in the future, once.
Parameters:
Name Type Argument Description runnerFnfunction The function to be executed after the provided time delay has passed. delaynumber The amount of time before the runner function is executed. contextobject <optional>
An object representing the scope of the runner function (also known as the "this" object). Throws:
An IllegalArgumentException Java exception if the delay is lower than or equal to 0.Returns:
A reference to the ScheduledFuture Java class representing the scheduled task; it is useful to keep a reference to this object, in case the task execution needs to be cancelled later.- Type
- ScheduledFuture
-
scheduleAtFixedRate(runnerFn, interval [, delay] [, context])
-
Schedules a new task to be executed periodically.
Parameters:
Name Type Argument Default Description runnerFnfunction The function to be executed at each interval. intervalnumber The interval at which the runner function should be executed. delaynumber <optional>
0 The initial amount of time before the runner function is executed for the first time. contextobject <optional>
An object representing the scope of the runner function (also known as the "this" object). Throws:
An IllegalArgumentException Java exception if the interval is lower than or equal to 0.Returns:
A reference to the ScheduledFuture Java class representing the scheduled task; it is useful to keep a reference to this object, in case the task execution needs to be cancelled later.- Type
- ScheduledFuture