UNPKG

actionhero

Version:

The reusable, scalable, and quick node.js API server for stateless and stateful applications

41 lines (40 loc) 1.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SleepTest = void 0; const index_1 = require("./../index"); function sleep(time) { return new Promise((resolve) => { setTimeout(resolve, time); }); } class SleepTest extends index_1.Action { constructor() { super(...arguments); this.name = "sleepTest"; this.description = "I will sleep and then return"; this.inputs = { sleepDuration: { required: true, formatter: parseInt, default: () => { return 1000; }, }, }; this.outputExample = { sleepStarted: 1420953571322, sleepEnded: 1420953572327, sleepDelta: 1005, sleepDuration: 1000, }; } async run({ params }) { const sleepDuration = params.sleepDuration; const sleepStarted = new Date().getTime(); await sleep(sleepDuration); const sleepEnded = new Date().getTime(); const sleepDelta = sleepEnded - sleepStarted; return { sleepStarted, sleepEnded, sleepDelta, sleepDuration }; } } exports.SleepTest = SleepTest;