developit / developit/greenlet

Make greenlet working with a pool of Promises

オープン
#43 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
question
主要言語
JavaScript
スター
4.7k
フォーク
97
PR マージ指標
30日以内にマージされた PR はありません

説明

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.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

Issue 内の validationAuto と validationAutoWorkerized のスニペットから始め、次に greenlet の worker 引数と戻り値の処理、および非同期入力に関するドキュメントや例を確認します。最小限のブラウザー例で Promise.all のフローを再現します。done によって、この使用方法がサポートされているかどうかを明確に判断し、必要な動作または制限事項を文書化できるようにします。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript
領域
web-dev
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
28/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。