Last active
February 27, 2016 11:20
-
-
Save marcusoftnet/387f973113360b14955e to your computer and use it in GitHub Desktop.
Promises... Aaaaah
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
/*global require, module*/ | |
var ApiBuilder = require('claudia-api-builder'), | |
api = new ApiBuilder(), | |
Promise = require('bluebird'); | |
module.exports = api; | |
// use a promise for asynchronous processing | |
api.get('/greet/{name}', function(request) { | |
'use strict'; | |
return Promise | |
.resolve(waitASecondHere()) | |
.then(function (data) { return data; }); | |
}); | |
// Mimicing doing a Dynamo getItem or something. | |
// in this case just returning a string | |
function waitASecondHere(){ | |
setTimeout(function () { | |
return "Some data!"; | |
}, 1000); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
btw, use
Promise.delay(delayInMs)
instead ofsetTimeout
; the problem with the original script was that you were resolving, so completing the promise flow, at the start