Skip to content

Commit c872551

Browse files
committed
Normative: Ban |> await
Given problems with all possibilities considered for await integration with pipeline, ban |> await within an async function as the initial option. When we have considered things further, we could add await integration as a follow-on feature. Relates to tc39#66
1 parent 0aeadab commit c872551

File tree

2 files changed

+22
-29
lines changed

2 files changed

+22
-29
lines changed

README.md

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,7 @@ As you can see, because the pipe operator always pipes a single result value, it
7878

7979
### Use of `await`
8080

81-
The pipeline operator allows a `Promise` to be `await`ed as follows:
82-
83-
```js
84-
promise |> await
85-
```
86-
87-
which is the equivalent of
88-
89-
```js
90-
await promise
91-
```
92-
93-
This is to allow you to `await` the result of an asynchronous function and pass it to the next function from within a function pipeline, as follows:
94-
95-
```js
96-
const userAge = userId |> fetchUserById |> await |> getAgeFromUser
97-
```
98-
99-
which is the equivalent of
100-
101-
```js
102-
const userAge = getAgeFromUser(await fetchUserById(userId))
103-
```
81+
The pipeline operator does not have any special integration with async/await in its initial version, due to [issues](https://github.com/tc39/proposal-pipeline-operator/issues/66) with various alternatives discussed. To leave space for future additions to integrate await support, the not-very-useful sequence `|> await` (which would otherwise await a function, not the result of calling a function) is a SyntaxError.
10482

10583
### Usage with Function.prototype.papp
10684

spec.html

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,21 @@ <h1>Syntax</h1>
3434
<ins>
3535
PipelineExpression[In, Yield, Await] :
3636
LogicalORExpression[?In, ?Yield, ?Await]
37-
PipelineExpression[?In, ?Yield, ?Await] `|>` LogicalORExpression[?In, ?Yield, ?Await]
37+
[~Await] PipelineExpression[?In, ?Yield, ?Await] `|>` LogicalORExpression[?In, ?Yield, ?Await]
38+
[+Await] PipelineExpression[?In, ?Yield, ?Await] `|>` [lookahead &lt;! {`await`}] LogicalORExpression[?In, ?Yield, ?Await]
3839
</ins>
3940
</emu-grammar>
4041
</emu-clause>
4142

4243
<emu-clause id=sec-pipeline-semantics>
4344
<h1>Semantics</h1>
44-
<emu-clause id=sec-pipeline-evaluation>
45-
<h1>Runtime Semantics: Evaluation</h1>
46-
<emu-grammar>PipelineExpression : PipelineExpression '|>` LogicalORExpression</emu-grammar>
45+
<emu-clause id="sec-pipeline-evaluate">
46+
<h1>Runtime Semantics: PipelineEvaluate</h1>
47+
PipelineEvaluate for _lhs_ and _rhs_ performs the following steps:
4748
<emu-alg>
48-
1. Let _argRef_ be the result of evaluating |PipelineExpression|.
49+
1. Let _argRef_ be the result of evaluating _lhs_.
4950
1. Let _arg_ be ? GetValue(_argRef_).
50-
1. Let _funcRef_ be the result of evaluating |LogicalORExpression|.
51+
1. Let _funcRef_ be the result of evaluating _rhs_.
5152
1. Let _func_ be ? GetValue(_funcRef_).
5253
1. If Type(_funcRef_) is Reference, then
5354
1. If IsPropertyReference(_funcRef_) is *true*, then
@@ -70,6 +71,20 @@ <h1>Runtime Semantics: Evaluation</h1>
7071
<emu-note>All calls to eval from a pipeline operator are indirect eval calls.</emu-note>
7172
<emu-note type="editor">This definition is somewhat duplicated from the definition of evaluating CallExpression; when merging with the main specification, a refactoring will be done to de-duplicate it.</emu-note>
7273
</emu-clause>
74+
75+
76+
<emu-clause id=sec-pipeline-evaluation>
77+
<h1>Runtime Semantics: Evaluation</h1>
78+
<emu-grammar>PipelineExpression : PipelineExpression `|>` LogicalORExpression</emu-grammar>
79+
<emu-alg>
80+
1. Let _result_ be the result of PipelineEvaluate for |PipelineExpression| and |LogicalORExpression|.
81+
1. Return _result_.
82+
</emu-alg>
83+
<emu-grammar>PipelineExpression : LogicalORExpression</emu-grammar>
84+
<emu-alg>
85+
1. Return the result of evaluating |LogicalORExpression|.
86+
</emu-alg>
87+
</emu-clause>
7388
<emu-clause id=sec-pipeline-has-call-in-tail-position>
7489
<h1>Static Semantics: HasCallInTailPosition</h1>
7590
<emu-grammar>PipelineExpression : PipelineExpression '|>` LogicalORExpression</emu-grammar>

0 commit comments

Comments
 (0)