JQuery .always
looks to be equivalent to .then(callback, callback)
, where you just pass the same callback function twice. Or https://github.com/kriskowal/q/wiki/API-Reference#promisefinallycallback
If you want to get really hacky, you could have a loop that checks the whether the promise is settled using promise.isPending()
and return
when it’s pending, but that wouldn’t make any sense for production code. I might be misunderstanding your intentions, but if you have code waiting on the result of the promise-returning method, you should take the result of method
and .then
it.
So, instead of:
var prom = method();
runAfterPromSettle();
do this:
var prom = method;
prom.then(runAfterPromSettle())
.catch(handleErrors());
--
You received this message because you are subscribed to the Google Groups "Q Continuum (JavaScript)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to q-continuum...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
If you want promiseShouldBeHandled()
to run after the promise resolves or rejects, then your code will be:
var prom = method();
prom.then(promiseShouldBeHandled,
promiseShouldBeHandled);
If you want three different code paths (promise is resolved, promise is rejected, promise is unsettled), then it would be best to rethink how you are structuring the code, because that doesn’t really align with the way promises should be used. It’s less of a branching control-flow mechanism, and more of a way of treating asynchronous code synchronously. Forgive me if I sound pedantic and that isn’t what you are going for.
If you expect that the promise might never settle, you could have a timeout and reject the promise after a certain amount of time.
--
You received this message because you are subscribed to the Google Groups "Q Continuum (JavaScript)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to q-continuum...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
The problem is that the output from the above is
Ah, yeah. Sorry for misunderstanding you. I guess if that’s the end of the program, then any non-blocking control-flow wouldn’t hold it up from exiting. Seems like a polling loop or some event loop is necessary.
If you don’t mind me asking, what’s the mechanism/function that’s causing a delay in promise resolution? If I use the following code, Node.js will wait until the timeout fires to exit.
var Q = require('q');
var prom = Q.Promise(function (resolve, reject) {
setTimeout(function () {
resolve('success');
}, 2000);
});
prom.then(function() {
console.log("Success");
}).catch(function(err) {
console.log("Failure");
});
console.log('Pending');
I’m curious about what asynchronous functions don’t hold up Node from exiting.
--
You received this message because you are subscribed to the Google Groups "Q Continuum (JavaScript)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to q-continuum...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
dfi.createNodes = function() {
return Q.Promise(function(resolve, reject) {
var config = {
server: 'db3dev',
database: 'EForms',
driver: 'msnodesqlv8',
options: {
trustedConnection: true
}
};
sql.connect(config).then(function() {
Are you sure that you are calling method? You don't seem to…
I'm sure that node doesn't exit as long as there is anything scheduled. You can verify yourself by also calling a setTimeout, node won't exit until that's done.
--
You received this message because you are subscribed to the Google Groups "Q Continuum (JavaScript)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to q-continuum...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Wout.
(typed on mobile, excuse terseness)