I just published my package dmihal:generator-method
, which allows some cool new functionality for methods.
Here’s a simple example:
Server:
Meteor.generatorMethod('myMethod', async function* test() {
yield { status: 'start' };
await wait(1);
yield { status: 'running', stage: 1 };
await wait(1);
yield { status: 'running', stage: 2 };
await wait(1);
yield { status: 'running', stage: 3 };
await wait(1);
yield { status: 'done' };
});
function wait(seconds) {
return new Promise(resolve => setTimeout(resolve, seconds * 1000));
}
Client:
async runSomeMethod() {
const handle = Meteor.callGenerator('myMethod');
for await (const response of handle) {
console.log(response);
}
}
I’d love some feedback, let me know what you think!