📦 NPM @5.0.0
☄️ Packosphere @5.0.0
What's New
- 🦄
async
/await
API for all public methods - 🚀 Return {Promise} from tasks instead of calling
ready()
Major Changes
⚠️ Drop support for callbacks⚠️ Renamed private methods for clarity⚠️ Renamed methods of "Adapter" API for clarity⚠️ opts.adapter
now expects instance of the StorageAdapter, was: Class of StorageAdapter⚠️ Movedopts.prefix
andopts.resetOnInit
to StorageAdapter's constructor⚠️ Moved storage-related optionsopts.client
,opts.db
, andlockCollectionName
to StorageAdapter's constructor
Changes
- ✨ New options {object} accepted by
new RedisAdapter({})
- ✨ New options {object} accepted by
new MongoAdapter({})
- 👨🔬 Refactored tests for the new async/await API
- 👨🔬 Refactored Meteor.js test-suite for the new async/await API
- 📔 Updated documentation
- 📔 Updated custom adapter documentation
v4 to v5 migration
Although setInterval
and setTimeout
now return {Promise} instead of {String} updated clearInterval
and clearTimeout
methods accept {Promise}, so migration might not be necessary. Next block of code will remain operational in v3
/v4
and v5
:
const taskId = job.setInterval((ready) => {
/* code here */
ready();
}, 2048, 'task-2048ms');
job.clearInterval(taskId);
Migration is necessary only if callbacks of clearInterval
and clearTimeout
were used. Callbacks need to get replaced by await
. setInterval
and setTimeout
will require using await
to obtain timerId
.
was in v3/v4:
const taskId = job.setInterval((ready) => {
/* code here */
ready();
}, 2048, 'task-2048ms');
job.clearInterval(taskId, () => {
// task cleared now
});
change to for v5:
const taskId = await job.setInterval((ready) => {
/* code here */
ready();
}, 2048, 'task-2048ms');
await job.clearInterval(taskId);
// task cleared now
Now it's possible to return promises, previously ready()
was required to call in v3/v4:
job.setInterval((ready) => {
/* code here */
ready();
}, 2048, 'task-2048ms');
now simply register async
function in v5:
job.setInterval(async () => {
/* code here */
}, 2048, 'task-2048ms');
or simply return promise in v5:
job.setInterval(() => {
/* code here */
return promisedValue; // instance of the Promise
}, 2048, 'task-2048ms');
or async
/await
the promise in v5:
job.setInterval(async () => {
/* code here */
return await promisedValue;
}, 2048, 'task-2048ms');
now calling ready()
inside async
function will not work in v5:
job.setInterval(async (ready) => {
/* code here */
ready(); // <-- won't run, will log a debug message here
}, 2048, 'task-2048ms');