forked from actionhero/actionhero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsleepTest.js
38 lines (31 loc) · 902 Bytes
/
sleepTest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict'
exports.sleepTest = {
name: 'sleepTest',
description: 'I will sleep and then return',
inputs: {
sleepDuration: {
required: true,
formatter: function (n) { return parseInt(n) },
default: function () { return 1000 }
}
},
outputExample: {
'sleepStarted': 1420953571322,
'sleepEnded': 1420953572327,
'sleepDelta': 1005,
'sleepDuration': 1000
},
run: function (api, data, next) {
const sleepDuration = data.params.sleepDuration
const sleepStarted = new Date().getTime()
setTimeout(function () {
const sleepEnded = new Date().getTime()
const sleepDelta = sleepEnded - sleepStarted
data.response.sleepStarted = sleepStarted
data.response.sleepEnded = sleepEnded
data.response.sleepDelta = sleepDelta
data.response.sleepDuration = sleepDuration
next()
}, sleepDuration)
}
}