actionhero
Version:
The reusable, scalable, and quick node.js API server for stateless and stateful applications
43 lines (42 loc) • 1.28 kB
JavaScript
;
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({ 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;