I want to make a function that calls an API (third party) and returns immediately, but it is waiting for API response.
Here is the code sample:
var request = require('request');
// When I call functionOne it should trigger functionTwo and should end immediately,
// but unfortunately, it is waiting for functionTwo to end
module.exports.functionOne = (event, context, cb) => {
const uri = 'https://xxxxxxxxx.execute-api.us-east-1.amazonaws.com/dev/functionTwo';
request.post({ uri: uri });
cb(null, "done functionOne");
};
module.exports.functionTwo = (event, context, cb) => {
console.log("i'm functionTwo");
setTimeout(function () {
console.log("I'm functionTwo about to end");
context.succeed("done functionTwo");
}, 5000);
};
Moreover, if i try to call context.succeed()
instead of cb()
, it even prevent API call and function return immediately without calling the API.
I have also created an issue on GitHub.
Additional info:
- Serverless Framework: v1.0.0-rc.2
- Node: v6.9.1
- OS: Win 10