Last active
March 23, 2017 23:43
-
-
Save evantahler/e62ab685b359d63c11ec572510b44466 to your computer and use it in GitHub Desktop.
Actionhero async actions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.asyncAwait = { | |
name: 'asyncAwait', | |
description: 'I am an asyncAwait action', | |
run: async function (api, data, next) { | |
let startTime = new Date().getTime() | |
let sleep = 1000 | |
let timerPromise = new Promise((resolve, reject) => { setTimeout(resolve, sleep) }) | |
try { | |
await timerPromise | |
data.response.message = `I slept for ${new Date().getTime() - startTime}ms` | |
return next() | |
} catch (e) { | |
return next(e) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment