Creates timed bundles of commands.
An example:
var bundle = create({foo: ['name', 'val'], bar: ['myArg']}, 2000)
bundle.foo(100, ['joe', 34]).bar(250, [43]).bar(100, [98]);
bundle.__iot_freeze__((new Date()).getTime() + 1000)
It creates a bundle with three commands: 'foo', ' bar', and 'bar' again.
The first one executes after 100msec of bundle activation, the second 250 msec after the first command starts, and so on...
The number of arguments needed for each command are described in the
constructor by providing the argument names. The CAs iot
plugin
introspects the iot_methods.js
at run time to create that configuration.
The bundle will activate in 3 seconds (1 sec plus the 2 second margin), if it arrives to the target before that time.
If we want to re-issue the bundle at a different time:
const newBundle = bundle.__iot_clone__();
newBundle.__iot_freeze__(NOW)
and now the bundle will start executing as soon as it arrives to the target.
- Source:
Members
MARGIN_IN_MSEC :number
- Source:
Default extra time to allow bundle propagation.
Type:
- number
NOW :number
- Source:
Force the bundle to execute as soon as it arrives to its destination.
Type:
- number
NOW_SAFE :number
- Source:
Force the bundle to execute as soon as it arrives to its destination unless it is really old.
Type:
- number
Methods
create(methodsopt, marginopt) → {bundleObjectType}
- Source:
Constructor.
Create timed bundle of commands.
The type bundleDescriptionType
is:
Object<string, Array.<string>>
where the key is the name of the command, and the value an array of strings with the argument names of this command.
The command should be a method described in the iot_methods.js
file.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
methods |
bundleDescriptionType |
<optional> |
Optional object with method names and arguments. |
margin |
number |
<optional> |
A safety time margin in msec added to the starting
time to allow bundle propagation. It defaults to |
Returns:
A new bundle with no commands.
- Type
- bundleObjectType
fromObject(bundleVanilla, methodsopt, marginopt) → {bundleObjectType}
- Source:
Creates a bundle from a 'vanilla' object representation.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
bundleVanilla |
bundleType | A 'vanilla' object representation of the
bundle. See |
|
methods |
bundleDescriptionType |
<optional> |
Optional object with method names and arguments. |
margin |
number |
<optional> |
A safety time margin in msec added to the starting
time to allow bundle propagation. It defaults to |
Returns:
A patched bundle.
- Type
- bundleObjectType
__iot_clone__() → {bundleObjectType}
- Source:
Clones this bundle to allow further modifications after freezing.
Returns:
A cloned bundle.
- Type
- bundleObjectType
__iot_freeze__(newStartopt) → {bundleObjectType}
- Source:
Fully initializes this bundle by setting the start execution time explicitly, or based on current time.
After this method a bundle is frozen, and needs to be cloned before it can be modified.
The starting time newStart
could be:
NOW
: whenever the bundle arrives to its target, it will start executing right away.NOW_SAFE
: same asNOW
but ignoring really old bundles.undefined
: use the current time plus themargin
specified in the factory method.number
: start time in msec since 1970/01/01 UTC plus themargin
as above. If negative assumed a preprocessedNOW_SAFE
request.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
newStart |
number |
<optional> |
An optional starting time (see above). |
Returns:
This bundle fully initialized.
- Type
- bundleObjectType
__iot_parse__(bundleString) → {bundleObjectType}
- Source:
Parses a serialized string to initialize this bundle with commands.
Parameters:
Name | Type | Description |
---|---|---|
bundleString |
string | A serialized bundle. |
Returns:
This bundle initialized with commands.
- Type
- bundleObjectType
__iot_serialize__() → {string}
- Source:
Creates a string representation of a fully initialized bundle.
Returns:
A serialized bundle.
- Type
- string
toObject(bundle) → {bundleType}
- Source:
Creates a 'vanilla' object representation of a bundle.
The type bundleType
is:
{start: number, commands: Array.<commandType>}
and commandType
:
{after: mumber, method: string, args: Array.<jsonType>}
Parameters:
Name | Type | Description |
---|---|---|
bundle |
bundleObjectType | A bundle to transform. |
Returns:
A 'vanilla' object representation of the bundle.
- Type
- bundleType