Helpers


Workflow implementations have constraints that prevent using non-deterministic functions or functions with side-effects (those should be located in tasks).

The handle or onEvent generator functions of a workflow are processed between each sequential task or for each event:

  • new Date() gives each time a different date
  • Math.random()gives each time a different value
  • console.log() prints each time in zenaton.out file

A solution is to embed those functions in a task - or to use the helpers below.

# Current date

A date function can be used within the handle or onEvent functions of a workflow to get a current Date object.

const now = this.date();

TIP

this.date() is equivalent to new Date(), but can be used inside a workflow.

# Random number

Using randomness in workflows can be useful, for example to A/B test them.

A random function can be used within the handle or onEvent functions of a workflow to get a random float between 0 and 1:

const rand = this.random();

TIP

this.random() is equivalent to Math.random(), but can be used inside a workflow.

# Logging

A log function can be used within the handle or onEvent functions of a workflow to log a string to zenaton.out file:

this.log("useful for debuging!");

TIP

this.log() is equivalent to console.log(), but can be used inside a workflow.