Hello,
I have problem with a promise that is requests from a render process to another process.
This process return the object promise and resolve it, but the render process not alwayse handles the promise well.
I have a setting page on a render process, which use ipc-promise to call a method from one module which return a promise. The first time I open this page the promise is correcty handled but, if I close this page and open it again the promise is returned and also it’s resolved correctly, but the function .then() of the promise is not fired.
This is my code:
setting page
var ipcPromise = require('ipc-promise');
function test(){
var res = ipcPromise.send('mainChannelPromise',
{ 'class':'CNetworkManager',
'method':'networkTest',
'param': ''
});
res.then(
//fired first time I open the browserWindow with this code
//not fired the second time
)
}
module on the other process
function networkTest(settings){
var reqOpts = {
url: "http://ron-swanson-quotes.herokuapp.com/v2/quotes",
method: "GET"
};
var resp = new Promise(function(resolve, reject) {
request(reqOpts, function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body); //performed every time
resolve(body);
}else{
console.log('err '+ error + ' type ' +typeof(error)); //never perfomed, link just works well
reject(error);
}
});
});
return resp;
}
module.exports = {
networkTest: networkTest
};
Thanks in advance for the help.