Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asyncFnのPromiseをawaitしない構文(案) #1543

Open
weyk opened this issue Oct 3, 2023 · 2 comments
Open

asyncFnのPromiseをawaitしない構文(案) #1543

weyk opened this issue Oct 3, 2023 · 2 comments

Comments

@weyk
Copy link
Contributor

weyk commented Oct 3, 2023

js実装命令のasyncFnにより自動的にawaitとすることで非同期含んだ命令も使いやすくなりました。
ただし、「ひとまず今は待たない」ということが出来ません。
そこで、「しつつ」「しながら」という命令or助詞を導入し、asyncFnの命令の呼び出しに「しつつ」が続く場合には
呼び出しにawaitを付加しない(変数に入れたらPromiseがそのまま入る)とするのはどうでしょうか。
・結果や待ち合わせた処理が不要ならばpromiseはそのまま捨てれば無駄な待ちが省ける
・複数を配列に入れてplugin_promiseの命令でまとめて待ち合わせることが可能
・単にawaitするタイミングをずらすだけでも無駄な待ちが減る

@kujirahand
Copy link
Owner

とても興味深いアイデアですね!
それでも、どんな時に使えるのか、具体例があると、仕様が詰めやすいですね。

「**しながら・・・」構文とすると、以下のような感じでしょうか。

URL1 = 「https://...」
URL2 = 「https://...」
URL1からHTTP取得しながら・・・P1
URL2からHTTP取得しながら・・・P2
[P1, P2]が成功した時には
  「成功」と表示。
ここまで

@kujirahand
Copy link
Owner

kujirahand commented Jan 1, 2024

「しながら」構文も良いのですが、「約束」構文も良さそうです。

URL1 = 「https://...」
URL2 = 「https://...」
URL1からHTTP取得する約束をP1に代入。
URL2からHTTP取得する約束をP2に代入。
[P1, P2]が成功した時には
  「成功」と表示。
ここまで

こちらの方がpromiseの訳と合っていて良いかも?!

しかも、構文にしなくても、「HTTP取得約束」という関数を定義するだけ。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants