Skip to content

Commit

Permalink
Normative: Ban |> await
Browse files Browse the repository at this point in the history
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
  • Loading branch information
littledan committed Nov 18, 2017
1 parent 4e6e457 commit 0b72fe4
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 30 deletions.
25 changes: 1 addition & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,30 +78,7 @@ As you can see, because the pipe operator always pipes a single result value, it

### Use of `await`

The pipeline operator allows the result of a `Promise`-returning function to be `await`ed as follows:


```js
x |> await f
```

which is the equivalent of

```js
await f(x)
```

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 |> await fetchUserById |> 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
6 changes: 0 additions & 6 deletions spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ <h1>Syntax</h1>
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]
[+Await] PipelineExpression[?In, ?Yield, ?Await] `|>` `await` LogicalORExpression[?In, ?Yield, ?Await]
</ins>
</emu-grammar>
</emu-clause>
Expand Down Expand Up @@ -81,11 +80,6 @@ <h1>Runtime Semantics: Evaluation</h1>
1. Let _result_ be the result of PipelineEvaluate for |PipelineExpression| and |LogicalORExpression|.
1. Return _result_.
</emu-alg>
<emu-grammar>PipelineExpression : PipelineExpression `|>` `await` LogicalORExpression</emu-grammar>
<emu-alg>
1. Let _result_ be the result of PipelineEvaluate for |PipelineExpression| and |LogicalORExpression|.
1. Return ? AsyncFunctionAwait(_result_).
</emu-alg>
<emu-grammar>PipelineExpression : LogicalORExpression</emu-grammar>
<emu-alg>
1. Return the result of evaluating |LogicalORExpression|.
Expand Down

0 comments on commit 0b72fe4

Please sign in to comment.