-
public class HeadlessJsTaskContext
Helper class for dealing with JS tasks. Handles per-ReactContext active task tracking, starting / stopping tasks and notifying listeners.
-
-
Method Summary
Modifier and Type Method Description static HeadlessJsTaskContext
getInstance(ReactContext context)
Get the task helper instance for a particular ReactContext. synchronized void
addTaskEventListener(HeadlessJsTaskEventListener listener)
Register a task lifecycle event listener. void
removeTaskEventListener(HeadlessJsTaskEventListener listener)
Unregister a task lifecycle event listener. boolean
hasActiveTasks()
Get whether there are any running JS tasks at the moment. synchronized int
startTask(HeadlessJsTaskConfig taskConfig)
Start a JS task. synchronized boolean
retryTask(int taskId)
Retry a running JS task with a delay. synchronized void
finishTask(int taskId)
Finish a JS task. synchronized boolean
isTaskRunning(int taskId)
Check if a given task is currently running. -
-
Method Detail
-
getInstance
static HeadlessJsTaskContext getInstance(ReactContext context)
Get the task helper instance for a particular ReactContext. There is only one instanceper context.
Note: do not hold long-lived references to the object returned here, asthat will cause memory leaks. Instead, just call this method on-demand.
-
addTaskEventListener
synchronized void addTaskEventListener(HeadlessJsTaskEventListener listener)
Register a task lifecycle event listener. Synchronized in order to prevent race conditions withfinishTask, as the listener will be invoked for already running tasks.
-
removeTaskEventListener
void removeTaskEventListener(HeadlessJsTaskEventListener listener)
Unregister a task lifecycle event listener.
-
hasActiveTasks
boolean hasActiveTasks()
Get whether there are any running JS tasks at the moment.
-
startTask
synchronized int startTask(HeadlessJsTaskConfig taskConfig)
Start a JS task. Handles invoking startHeadlessTask and notifyinglisteners.
-
retryTask
synchronized boolean retryTask(int taskId)
Retry a running JS task with a delay. Invokes as long as the process does not getkilled.
-
finishTask
synchronized void finishTask(int taskId)
Finish a JS task. Doesn't actually stop the task on the JS side, only removes it from the listof active tasks and notifies listeners. A task can only be finished once.
- Parameters:
taskId
- the unique id returned by startTask.
-
isTaskRunning
synchronized boolean isTaskRunning(int taskId)
Check if a given task is currently running. A task is stopped if either finishTask iscalled or it times out.
-
-
-
-