<abstract> new Executor( [context] [, autoDestroy])
Creates an Executor and binds it to an olympe.df.ExecutionContext. Defaults to the current context.
Parameters:
| Name | Type | Argument | Description |
|---|---|---|---|
context |
olympe.df.ExecutionContext |
<optional> |
The |
autoDestroy |
boolean |
<optional> |
|
Members
-
<protected, non-null> callbacks :Array.<function(boolean, ?string, Map.<string, *>)>
-
Type:
- Array.<function(boolean, ?string, Map.<string, *>)>
-
<protected> ended :boolean
-
Type:
- boolean
-
<protected, non-null> env :Map.<string, *>
-
Type:
- Map.<string, *>
-
<protected, nullable> errorMsg :string
-
Type:
- string
-
<protected> logger :olympe.logging.Channel
-
Type:
- olympe.logging.Channel
-
<protected> started :boolean
-
Type:
- boolean
-
<protected, non-null> tasks :Array.<olympe.async.Task>
-
Type:
- Array.<olympe.async.Task>
Methods
-
<static> runWithTimeout(task, timeout)
-
Executes a single asynchronous task with a given timeout. If the tasks doesn't complete within the specified time frame, the associated
Executorwill be completed as failed. AnExecutionContextwill be automatically created at the start and destroyed on completion.Parameters:
Name Type Description taskolympe.async.Task The task to execute.
timeoutnumber The timeout in milliseconds.
Returns:
The created
Executor. -
add(task)
-
Adds a task to this Executor. If the executor has already ended, this is ignored.
Parameters:
Name Type Description taskolympe.async.Task The task to add.
Returns:
this
Executor. -
<protected> clear()
-
Clears the executor: remove all tasks and callbacks.
-
<protected> complete(success)
-
Notifies the end of the execution and triggers the callbacks.
Parameters:
Name Type Description successboolean Whether the execution was successful or not.
-
getContext()
-
Gets the
ExecutionContextassociated with this Executor.Returns:
-
getLogger()
-
Gets the logger attached to this Executor.
Returns:
The attached logger.
- Type
- olympe.logging.Channel
-
hasEnded()
-
Checks whether this
Executorhas completed its execution.Returns:
truewhen theExecutorhas ended.- Type
- boolean
-
isRunning()
-
Checks whether this
Executoris currently running one or more tasks.Returns:
truewhen theExecutoris running.- Type
- boolean
-
onEnd(callback)
-
Registers a callback to be called when the Executor has completed. The callback is passed a boolean,
trueif all the tasks completed successfully,falseotherwise.Parameters:
Name Type Description callbackfunction The function to register.
Returns:
this
Executor. -
start()
-
Starts the executor. Does nothing if it had already been started.
-
withLogger(logger)
-
Attach a logger to this executor.
Parameters:
Name Type Description loggerolympe.logging.Channel The logger to attach.
Returns:
this
Executor. -
withTimeout(t)
-
Sets a timeout for the executor. If all the tasks in this
Executorare not completed within the specified time the Executor will complete asfailed. All pending tasks will be cancelled.Parameters:
Name Type Description tnumber timeout in milliseconds.
Returns:
this
Executor.
Olympe SDK