「await」ページのサンプルコードにasyncを追加しました。 - #1144
Open
suin wants to merge 1 commit into
Open
Conversation
## 対象者
- [x] 📖 読者
## Problem
「拒否された`Promise`を`return`するとき」>「`return`の前に`await`しない」のサンプルで `request` に `async` が付いておらず、`throw` が同期例外になっていました。そのため実行結果が本文記載の `finally` / `catch` ではなく `error` / `finally` / `then` となり、直前セクションとの比較も成立していませんでした。
## Solution
`request` に `async` を追加し、直前セクションと定義を揃えました。
```ts
-function request(): Promise<unknown> {
+async function request(): Promise<unknown> {
```
出力が本文どおり `finally` / `catch` になることを実行して確認済みです。
## Value
読者がサンプルを実行したとき本文どおりの結果が得られ、`return await` と `return` の違いを正しく理解できるようになります。
---
Close #1133
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
対象者
Problem
「拒否された
Promiseをreturnするとき」>「returnの前にawaitしない」のサンプルでrequestにasyncが付いておらず、throwが同期例外になっていました。そのため実行結果が本文記載のfinally/catchではなくerror/finally/thenとなり、直前セクションとの比較も成立していませんでした。Solution
requestにasyncを追加し、直前セクションと定義を揃えました。出力が本文どおり
finally/catchになることを実行して確認済みです。Value
読者がサンプルを実行したとき本文どおりの結果が得られ、
return awaitとreturnの違いを正しく理解できるようになります。Close #1133