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

Normative: Ban |> await #73

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 1 addition & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,7 @@ As you can see, because the pipe operator always pipes a single result value, it

### Use of `await`

The pipeline operator allows a `Promise` to be `await`ed as follows:

```js
promise |> await
```

which is the equivalent of

```js
await promise
```

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:

```js
const userAge = userId |> fetchUserById |> await |> getAgeFromUser
```

which is the equivalent of

```js
const userAge = getAgeFromUser(await fetchUserById(userId))
```
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.

### Usage with Function.prototype.papp

Expand Down
27 changes: 21 additions & 6 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,21 @@ <h1>Syntax</h1>
<ins>
PipelineExpression[In, Yield, Await] :
LogicalORExpression[?In, ?Yield, ?Await]
PipelineExpression[?In, ?Yield, ?Await] `|>` LogicalORExpression[?In, ?Yield, ?Await]
[~Await] PipelineExpression[?In, ?Yield, ?Await] `|>` LogicalORExpression[?In, ?Yield, ?Await]
[+Await] PipelineExpression[?In, ?Yield, ?Await] `|>` [lookahead &lt;! {`await`}] LogicalORExpression[?In, ?Yield, ?Await]
</ins>
</emu-grammar>
</emu-clause>

<emu-clause id=sec-pipeline-semantics>
<h1>Semantics</h1>
<emu-clause id=sec-pipeline-evaluation>
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>PipelineExpression : PipelineExpression '|>` LogicalORExpression</emu-grammar>
<emu-clause id="sec-pipeline-evaluate">
<h1>Runtime Semantics: PipelineEvaluate</h1>
PipelineEvaluate for _lhs_ and _rhs_ performs the following steps:
<emu-alg>
1. Let _argRef_ be the result of evaluating |PipelineExpression|.
1. Let _argRef_ be the result of evaluating _lhs_.
1. Let _arg_ be ? GetValue(_argRef_).
1. Let _funcRef_ be the result of evaluating |LogicalORExpression|.
1. Let _funcRef_ be the result of evaluating _rhs_.
1. Let _func_ be ? GetValue(_funcRef_).
1. If Type(_funcRef_) is Reference, then
1. If IsPropertyReference(_funcRef_) is *true*, then
Expand All @@ -70,6 +71,20 @@ <h1>Runtime Semantics: Evaluation</h1>
<emu-note>All calls to eval from a pipeline operator are indirect eval calls.</emu-note>
<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>
</emu-clause>


<emu-clause id=sec-pipeline-evaluation>
<h1>Runtime Semantics: Evaluation</h1>
<emu-grammar>PipelineExpression : PipelineExpression `|>` LogicalORExpression</emu-grammar>
<emu-alg>
1. Let _result_ be the result of PipelineEvaluate for |PipelineExpression| and |LogicalORExpression|.
1. Return _result_.
</emu-alg>
<emu-grammar>PipelineExpression : LogicalORExpression</emu-grammar>
<emu-alg>
1. Return the result of evaluating |LogicalORExpression|.
</emu-alg>
</emu-clause>
<emu-clause id=sec-pipeline-has-call-in-tail-position>
<h1>Static Semantics: HasCallInTailPosition</h1>
<emu-grammar>PipelineExpression : PipelineExpression '|>` LogicalORExpression</emu-grammar>
Expand Down