UNPKG

actionhero

Version:

actionhero.js is a multi-transport API Server with integrated cluster capabilities and delayed tasks

46 lines (45 loc) 1.4 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(); this.name = "sleepTest"; this.description = "I will sleep and then return"; this.inputs = { sleepDuration: { required: true, formatter: (n) => { return parseInt(n); }, default: () => { return 1000; }, }, }; this.outputExample = { sleepStarted: 1420953571322, sleepEnded: 1420953572327, sleepDelta: 1005, sleepDuration: 1000, }; } async run({ response, params }) { const sleepDuration = params.sleepDuration; const sleepStarted = new Date().getTime(); await sleep(sleepDuration); const sleepEnded = new Date().getTime(); const sleepDelta = sleepEnded - sleepStarted; response.sleepStarted = sleepStarted; response.sleepEnded = sleepEnded; response.sleepDelta = sleepDelta; response.sleepDuration = sleepDuration; } } exports.SleepTest = SleepTest;