winglang / wing

A programming language for the cloud ☁️ A unified programming model, combining infrastructure and runtime code into one language ⚡
https://winglang.io
Other
5.06k stars 198 forks source link

Function Types: Promise #1004

Open eladb opened 1 year ago

eladb commented 1 year ago

Feature Spec

https://github.com/winglang/wing/blob/main/docs/04-reference/winglang-spec.md?rgh-link-date=2022-11-10T13%3A18%3A56Z#362-promises

Support for Promise.xxx use cases. It is now possible to implement advanced concurrency flows using the promise API:

These statements behave like their JavaScript Promise.xxx counterparts.

  1. Promise.all(p1, p2, ...)
  2. Promise.any(p1, p2, ...)
  3. Promise.all_settled(p1, p2, ...)
  4. Promise.race(p1, p2, ...)

The result is a promise that needs to be explicitly awaited.

For example, let's say I want to wait for two async operations to succeed before continuing the flow:

let p1 = defer async1();
let p2 = defer async2();
await Promise.all(p1, p2);

In this suggestion, the Promise type is similar to other built-in types like Set, Map, ...

Use Cases

Advanced concurrency

Implementation Notes

No response

Component

Compiler

Chriscbr commented 1 year ago

Should promise be the name of some global object, or should it require bring promise;?

(I'm guessing we should minimize global namespace pollution in our language if possible)

ShaiBer commented 1 year ago

I agree that we should minimize, but think promise should be there

eladb commented 1 year ago

We should consider various syntax options.

I actually think the JS syntax is pretty solid, so it could be just Promise.xxx() (same as we have Array and Set..,

eladb commented 1 year ago

Updated the description to use capital letter

github-actions[bot] commented 1 year ago

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!

github-actions[bot] commented 1 year ago

Hi,

This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. Feel free to re-open this issue when there's an update or relevant information to be added. Thanks!