I’m not sure how you would block JavaScript to actually make it synchronous since it is an asynchronous language. I use the “circular” method I described in one of my modules with very little lag; yes you would have to break it up into two functions for part A and part B.
Is the GET you are mentioning just getting a config value from the module’s config? If so, why not just pass the config value you need with a module.js->node_helper socket notification and have the node_helper store the value until you need it? Any time it needs to be updated, just resend the notification; that way node_helper always has the latest value available.
node_helper.js:
module.exports = NodeHelper.create({
config: {},
socketNotificationReceived: function(notification, payload) {
if (notification === 'CONFIG') {
this.config = payload;
}
},
yourFunction: function(variables) {
configValueNeeded = this.config.valueNeeded;
... // do something
},
...
});
module.js:
start: function() {
this.updateConfig();
},
updateConfig: function() {
this.sendSocketNotification('CONFIG', this.config);
},
someFunction: function() {
// config changed for some reason
this.updateConfig();
},
If you’re getting a config value from some third-party service: in your node_helper you can use the request module:
getData: function() {
// DO STUFF
var request = require('request');
request({
url: apiUrl,
method: 'GET',
}, (error, response, body) => {
if (!error && response.statusCode == 200) {
// CONTINUE DOING YOUR STUFF
} else if (response.statusCode === 401) {
console.error(this.name, error);
} else {
console.error(this.name, "Could not load data.");
}
});
},