Await/Defer Statement
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.4k
- Forks
- 215
- Avg merge
- 2h 9m
- Merged PRs (30d)
- 27
Description
The following section should be added to the language reference:
Contrary to JavaScript, any call to an async function is implicitly awaited in Wing. As
a result, await in Wing is a rarely used keyword, since its use is implied by
the inflight keyword. await is only used when you want a defered Promise
to be fulfilled before execution flow continues.
The Wing compiler emits awaits when encountering Promise<T> types as r-values
in expressions. Use the defer keyword to defer the resolution of a promise and
obtain a Promise<T> type instead (a.k.a unawait what the compiler does).
"defer" prevents the compiler from awaiting a promise and grabs a reference.
"await" and "Promise" are semantically similar to JavaScript's promises.
"await" statement is only valid in inflight function declarations.
Awaiting non promises in Wing is a no-op just like in JavaScript.
// Wing program: class MyClass { inflight foo(): num { let w = defer somePromise(); let x = await w; return x; } inflight boo(): num { let x = somePromise(); return x; } }
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file or test is named; start by locating the language reference and review the existing sections for async functions, inflight declarations, and Promise behavior. Add the supplied Await/Defer Statement section with its Wing example, and consider the work done when the reference explains the stated await, defer, and implicit-await semantics.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100