Home Intro Source Mebo GitHub
import Tasks from 'mebo/src/Tasks.js'
public class | source

Tasks

Object that holds actions and promises, which are executed at specific events.

Inside Mebo tasks are used by the Session.wrapup to hold actions and promises that are triggered when a Session is about to be terminated (Session.finalize).

Constructor Summary

Public Constructor
public

Creates a new instance

Method Summary

Public Methods
public

addAction(action: Action, options: Object)

Adds an action to the tasks

public

addWrappedPromise(wrappedPromise: function, options: Object)

Adds a wrapped promise to the tasks

public

clear()

Resets the tasks by cleaning all actions and promises

public

async contents(actions: boolean, promises: boolean): Promise<Array>

Returns a list sorted by priority and inclusion order about the actions and promises that are executed through execute

public

Tells if there are no tasks

public

async run(): Promise<Array>

Executes the actions and promises inside of the tasks (provided by contents).

Public Constructors

public constructor() source

Creates a new instance

Public Methods

public addAction(action: Action, options: Object) source

Adds an action to the tasks

runOnlyOnce can be used to avoid the execution of an action that may be triggered multiple times across nested actions where ideally it should be executed only once, it's done by using the action's id (Action.id).

Params:

NameTypeAttributeDescription
action Action

action instance that should be executed in the wrap up

options Object

custom options

options.runOnlyOnce boolean
  • optional
  • default: true

tells if the action should be ignore in case it has already been executed previously (it's done by matching the Action.id)

options.priority number
  • optional
  • default: 100

tells the priority of the action, this affects the execution order where a lower numeric value means a higher priority.

public addWrappedPromise(wrappedPromise: function, options: Object) source

Adds a wrapped promise to the tasks

Params:

NameTypeAttributeDescription
wrappedPromise function

function that should return a promise, ex:

tasks.addWrappedPromise(() => Promise.resolve(3))
options Object

custom options

options.priority number
  • optional
  • default: 100

tells the priority of the action, this affects the execution order where a lower numeric value means a higher priority.

public clear() source

Resets the tasks by cleaning all actions and promises

public async contents(actions: boolean, promises: boolean): Promise<Array> source

Returns a list sorted by priority and inclusion order about the actions and promises that are executed through execute

Params:

NameTypeAttributeDescription
actions boolean
  • optional
  • default: true

tells if the result should return the actions

promises boolean
  • optional
  • default: true

tells if the result should return the promises

Return:

Promise<Array>

public isEmpty(): boolean source

Tells if there are no tasks

Return:

boolean

public async run(): Promise<Array> source

Executes the actions and promises inside of the tasks (provided by contents). All tasks get executed even if an error occurs during the execution of an specific task. In case this method is triggered multiple times it ensures each task is only executed once.

Failed tasks are reported through an exception raised after all tasks have been executed, this error provides the taskMeboErrors member that contains a list about the errors raised during the execution of the tasks.

Return:

Promise<Array>

Returns an array containing each result of the tasks