Skip to content

Instantly share code, notes, and snippets.

@evantahler
Last active March 23, 2017 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evantahler/e62ab685b359d63c11ec572510b44466 to your computer and use it in GitHub Desktop.
Save evantahler/e62ab685b359d63c11ec572510b44466 to your computer and use it in GitHub Desktop.
Actionhero async actions
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