developit / developit/greenlet
Make greenlet working with a pool of Promises
- 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
Research direction
Start with the validationAuto and validationAutoWorkerized snippets in the issue, then read greenlet's worker argument and return-value handling and its documentation or examples for asynchronous inputs. Reproduce the Promise.all flow in a minimal browser example; done should clearly establish whether this usage is supported and document the required behavior or limitations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- web-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100