new Step()
A Step object to control the execution of a function via a Promise
Members
-
<static, constant> STATE_CANCELED
-
FINAL STATE The step got cancelled before the end of its execution
-
<static, constant> STATE_COMPLETED
-
State of a Step which function got completed (not final state)
-
<static, constant> STATE_FAILED
-
FINALE STATE The step failed
-
<static, constant> STATE_PASSED
-
FINAL STATE The step passed
-
<static, constant> STATE_PAUSED
-
State of a hobs.Chaining.Step currently paused
-
<static, constant> STATE_RESUMED
-
State of a Step having been resumed after getting paused
-
<static, constant> STATE_RUNNING
-
State of a Step currently being executed
-
<static, constant> STATE_STOPPED
-
Default state of a Step instance. Not yet executed
Methods
-
cancel()
-
Cancels step execution
-
done(state, result)
-
Completes step execution
Parameters:
Name Type Description state
string The final state of the step
result
object The result of the step execution
-
exec( [options])
-
Executes the step. It consists of executing the function passed to the constructor.
Parameters:
Name Type Argument Description options
Object <optional>
Extra properties, extending the ones set at the instantiation of the step and passed, as first argument, to the step function.
Returns:
A promise
- Type
- Object
-
options(name, value)
-
Get/set options of the step
Parameters:
Name Type Description name
string The name of the option property
value
* The value to set the option property to
Example
// Init Step with options var step = new hobs.Chaining.Step(null, {prop1: 'string', prop2: 12}); // Get all the options as an Object step.options(); // => {prop1: 'string', prop2: 12} // Get the value of a specific option property step.options('prop1'); // => 'string' step.options('prop2'); // => 12 // Set the value of a specific option property step.options('prop1', true); step.options('prop2', 123); step.options(); // => {prop1: true, prop2: 123}
-
pause()
-
Pauses step execution
-
resume()
-
Resumes execution of a paused step
Throws:
Will throw an error if the step is not paused
-
state()
-
Returns the current state of the step
Returns:
- Type
- String