I was working on custom unity cloud build integration for our team's slack channel. And got stuck with making proper callback. It looks like returning null before the asyc task being completed, So need some help in making proper async callback. I've included the script and console.log result.
var request = require('request');
var config = require('../../config.js');
var slackManager = require('../slack/slackmanager.js');
module.exports = {
AlertSlack: function (payload) {
var getLink = GetLink(payload);
console.log(getLink.next());
slackManager.alertSlack(getLink.next().value);
}
}
function* GetLink(payload) {
try {
var shareEndPointURL = config.unity.apibaseurl + payload.links.api_self.href + "/share";
var shareID = yield HttpRequestHandler(shareEndPointURL, 'GET');
//space to yield more httpRequest
//space to yield more httpRequest
//space to yield more httpRequest
return " some final data ";
} catch (e) {
console.log("Exception : " + e);
return e;
}
}
function HttpRequestHandler(endpointURL, httpMethod) {
var options = {
url: endpointURL,
method: httpMethod,
headers: config.unity.unityAuthHeaders
}
request(options, function (err, resp, body) {
console.log(body);
return body;
});
}
And here's the console log
{ value: undefined, done: false }
<-----recived call in slackmanager.js with ### some final data ###----->
{"shareid":"dfgdfgszdffzc"}