1.0.0-beta-4 • Published 6 years ago

@pageobject/engine v1.0.0-beta-4

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

@pageobject/engine Package Version Build Status Coverage Status

This package allows you to execute unreliable, asynchronous, and idempotent commands reliably.

Installation

yarn add @pageobject/engine

API

Please find the API documentation here.

Usage

Import the package

ES2015 modules

import {createRetryEngine} from '@pageobject/engine';

CommonJS

const {createRetryEngine} = require('@pageobject/engine');

Create a retry engine

const defaultTimeout = 10000 /* 10 seconds */;

const {retryOnError} = createRetryEngine(defaultTimeout);

Execute an idempotent command

const erroneousTwoTimes = async () => /* ... */;

In the following, the erroneousTwoTimes command is executed a total of 3 times. The third time the execution ends successfully.

retryOnError(erroneousTwoTimes).then(() => {
  console.log('Yeah!');
});
const neverEnding = async () => /* ... */;

The following execution of the neverEnding command results in a timeout error after 10 seconds.

retryOnError(neverEnding).catch(() => {
  console.error('Oops!');
});

The following execution of the neverEnding command results in a timeout error after 5 seconds.

const timeout = 5000 /* 5 seconds */;

retryOnError(neverEnding, timeout).catch(() => {
  console.error('Oops!');
});

Built by (c) Clemens Akens. Released under the terms of the MIT License.