Tasks

December 17, 2022 ยท View on GitHub

Functions


setTimeout

Schedules a function to be called after a specified delay.

Arguments

argument nametypedefaultValuedescription
callbackfunctionThe function to be called after the specified delay.
durationfloat0.01The delay in seconds before calling the function.
sendModestring"none"The send mode to use when calling the function. Possible values are "none", "queued", and "direct".
scopeobjectThe object to use as the "this" value when calling the function.
parentmc.types.nodeThe parent node to attach the timer to.

Returns timer - mc.types.node



setInterval Schedules a function to be called repeatedly at a specified interval.

Arguments

argument nametypedefaultValuedescription
callbackfunctionThe function to be called at the specified interval.
durationfloat0.01The interval in seconds between calls to the function.
sendModestring"none"The send mode to use when calling the function. Possible values are "none", "queued", and "direct".
scopeobjectThe object to use as the "this" value when calling the function.
parentmc.types.nodeThe parent node to attach the timer to.

Returns timer - mc.types.node



cancelTimeout

Cancels a previously scheduled timeout.

Arguments

argument nametypedefaultValuedescription
timermc.types.nodeThe timer node to be canceled


createTask

Creates a task node of the specified taskType with the provided fields and returns it.

Arguments

ArgumentTypeDefault ValueDescription
taskTypestringN/AThe type of task node to create.
fieldsobjectN/AAn object containing the fields to set on the created task node.
callbackfunctioninvalidA function to call when the task node's fieldName field changes.
isRunningbooleantrueWhether the task should start running immediately after it is created.
sendModestring"value"The send mode to use when observing the task node's fieldName field. Possible values are "value", "diff", and "none".
scopeobjectinvalidThe scope to use when calling the callback function.
fieldNamestring"output"The name of the field to observe on the task node.

Returns mc.types.node

TypeDescription
objectThe created task node. If the task node could not be created, returns invalid.

observeNodeField

Observes the given fieldName field on the node and calls the callback function when the field changes. If sendMode is set to "fieldAndValue", the fieldAndValueTargetField is set to the field name and value when the callback function is called. If once is set to true, the observer is removed after the first field change. If a scope is provided, the callback function is called with the scope as the this value. If callback is a string, it is assumed to be a member of the scope object and is called as a method on the scope object.

Arguments

Argument nameTypeDefault valueDescription
nodemc.types.nodeN/AThe node to observe.
fieldNamestringN/AThe name of the field to observe.
callbackfunctionN/AThe function to call when the value of the field changes.
sendModestring"value"Determines what value should be passed to the callback function when it is called. Can be "value" or "fieldAndValue".
oncebooleanfalseIf true, the callback will be called only once, then the observer will be removed.
scopeobjectinvalidThe object that the callback function is a member of, if it is a member function.
fieldAndValueTargetFieldstringinvalidThe field to set on the scope object when the sendMode is "fieldAndValue".

Returns

boolean: true if the observer was successfully set up, false if there was an error.


unObserveNodeField

This method removes a callback from observing a specific field of a node.

Arguments

Argument NameTypeDefault ValueDescription
nodemc.types.nodeN/AThe node to unobserve.
fieldNamestringN/AThe name of the field to unobserve.
callbackfloatN/AThe callback function to remove from observing the field.
scopeobjectinvalidThe scope to which the callback belongs.

cleanNodeObserver

This method is used to remove all observers for a particular field on a node.

Arguments

argument nametypedescription
nodemc.types.nodeThe node whose observers should be removed.
fieldNamestringThe name of the field whose observers should be removed.

cleanScope

This method is used to remove all observers for the current scope.



cancelTask

This method is used to stop a task and remove any observers for the task's output field.

Arguments

argument nametypedescription
taskmc.types.nodeThe task to stop and remove observers for.


ValueObserver

Class summary

The ValueObserver class allows you to observe a field on a node and define callback functions to be executed when the value of the field matches certain conditions. The conditions are specified using comparators such as "=" for equality, ">" for greater than, "<" for less than, etc.

Methods


new

Constructs a new instance of the ValueObserver class.

Arguments

argument nametypedefaultValuedescription
nodemc.types.nodeThe node to observe.
fieldstringThe field of the node to observe.
targetobjectThe object to execute the callback in.

reset

Resets the pendingComparators field.

Arguments

argument nametypedefaultValuedescription
hardResetbooleanfalseIf true, resets the comparators field as well.

destroy

Stops observing the node and field and removes all comparators.

Arguments

None.


onValue

Registers a callback to be executed when the observed field has a value matching the specified value and comparator.

Arguments

argument nametypedefaultValuedescription
valuedynamicThe value to compare the observed field value against.
funcfunctionThe callback to execute when the comparison is true.
comparatorstring"="The comparator to use for the comparison. Can be "=", ">", ">=", "<", "<=", or "<>".
modestring"value"The mode of the callback. Can be "value", "field", or "both".

valueCallback

Compares the value of the observed field against the registered comparators and executes the corresponding callback if a match is found.

Arguments

argument nametypedefaultValuedescription
valuedynamicThe value of the observed field.
nodemc.types.nodeThe node being observed.


TaskRunner

Class summary

A class that allows you to create and run a group of tasks. It provides support for running tasks in either parallel or sequential mode and has the ability to cancel or reset the group of tasks.


Methods


run

Starts the group of tasks.

Arguments

argument nametypedefaultValuedescription
callbackfunctionnoneA function to be called when all tasks are complete
runModestring"sequential"The mode in which to run the tasks. Can be "sequential" or "parallel".
tasksmc.types.arrayinvalidAn optional array of tasks to run. If not provided, the tasks property of the class will be used.

createTask

Adds a new task to the group of tasks.

Arguments

argument nametypedefaultValuedescription
taskTypestringnoneThe type of task to create.
fieldsmc.types.assocarraynoneAn associative array of fields to set on the task.
callbackfunctioninvalidAn optional callback function to be called when the task is complete.
sendModestring"value"The mode in which to send the value of the task's field to the callback function. Can be "value", "field", or "both".
fieldNamestring"output"The name of the field to observe on the task.

cancel

Cancels the group of tasks.

reset

Resets the group of tasks.