Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dmihal/generator-method

Meteor package to support methods that yield multiple times.
https://github.com/dmihal/generator-method

meteor meteorjs

Last synced: 23 days ago
JSON representation

Meteor package to support methods that yield multiple times.

Awesome Lists containing this project

README

        

# generator-method

## Install

```
meteor add dmihal:generator-method
```

## Example

### Server:

```javascript
Meteor.generatorMethod('test', 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:

```javascript
async runSomeMethod() {
const handle = Meteor.callGenerator('test');

for await (const response of handle) {
console.log(response);
}
}
```