developit / developit/greenlet
Make greenlet working with a pool of Promises
- Lingua principale
- JavaScript
- Stelle
- 4.7k
- Fork
- 97
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.