For starters this would help with the tests being nested 4+ levels deep.
For example.
afterEach(done => {
setTimeout(() => {
jobs.stop(() => {
clearJobs(() => {
mongo.close(() => {
jobs._mdb.close(done);
});
});
});
}, 50);
});
Ref for my own use later on: https://futurestud.io/tutorials/callback-and-promise-support-in-your-node-js-modules
So looks like we just need to wrap the return this in a promise that resolves this.
module.exports = function() {
const self = this;
return new Promise(resolve => resolve(self));
};
This allows both of these to work.
const agenda = new Agenda();
agenda.cancel().then(async agenda => {
console.log('cancelled') ;
await agenda.stop().close();
});
const agenda = new Agenda();
agenda.cancel(() => {
console.log('cancelled') ;
agenda.stop(() => {
agenda().close();
});
});
@agenda/maintainers thoughts?
馃憤
Seems like a reasonable path forward.
Since all tests are passing after making this change to a few files it looks like we should be fine adding this it breaking anything.
I'd do some more testing but I think we may be able to land this in 1.1.0. 馃檹
Awesome!
We should also support job definitions returning a function or a promise.
Please have a look here in the meanwhile https://github.com/agenda/agenda/pull/532
Added a small example that could help inexperienced people like myself.
馃檹 馃帀
Any news on promise support? It can be a very good feature if it can support promises on all methods so you can call agenda functions with async/await.
This is a deal-breaker for me. Any update on when this will be implemented?
@toddhickerson we've been working on it. https://github.com/agenda/agenda/pull/557
@toddhickerson @elias-garcia help testing and reviewing #557 always very much appreciated to move things onwards faster! ;-)
https://github.com/agenda/agenda/pull/557 is now merged :tada:
Most helpful comment
https://github.com/agenda/agenda/pull/557 is now merged :tada: