developit / developit/greenlet

Make greenlet working with a pool of Promises

Open
#43 2 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
JavaScript
Stars
4.7k
Forks
97
PR merge metrics
No merged PRs in 30d

Description

Hi guys, maybe I'm wrong and need to give it a better look at service workers but what I'm trying to accomplish is the following:

1- I'd like to pass to greenlet an array of promises like the Promise.all(promises) return.
2- Await for them inside the greenlet function.
3- returning the result to the main app.

This is my code:

```
try {
const promises = validationAuto(chunk, workarea, criteria, test_groups);
if (window.Worker) {
validationAutoWorkerized(promises);
} else {
await promises;
}
} catch (error) {
console.log(error);
}
```

```
const validationAuto = (chunk, workarea, criteria, test_groups) => {
const validationPromises = chunk.map(id => {
return new Promise((resolve, reject) => {
postWorkareaValidationAuto(workarea, id, criteria, test_groups)
.then(response => resolve(response))
.catch(error => reject(error));
});
});
return Promise.all(validationPromises);
};
```

```
const validationAutoWorkerized = greenlet(async promises => {
const data = await promises;
console.log(data);
return data;
});
```

Any tip to accomplish it with greenlet? Thanks.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.