Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community. Pick a username Email Address Password Sign up for GitHub 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
When writing async functions, there are differences between await vs return vs return await, and picking the right one is important. Let's start with this async function: async function waitAndMaybeReject() { // Wait one second await new Promise((r) => setTimeout(r, 1000)); // Toss a coin const isHeads = Boolean(Math.round(Math.random())); if (isHeads) return 'yay'; throw Error('Boo!'); } This ret
追記 (2020-08-05) 投稿時には async/await が Swift 5 で導入されそうでしたが、 2020 年 8 月( Swift 5.2 )現在ではまだ async/await は導入されておらず、 Swift 6 での導入が有力になっています。 async/await は "Swift Concurrency Manifesto" の最初の Part に挙げられていますが、公式にアナウンスされた "On the road to Swift 6" の中で Concurrency が挙げられています。 先日、 async に関する PR が Swift リポジトリの master ブランチにマージされました。 2ヶ月ほど前、 Chris Lattner から swift-evolution に "async/await + actors" というタイトルで驚きのメールが流
Show navigation Promise.prototype.finally enables registering a callback to be invoked when a promise is settled (i.e. either fulfilled or rejected). Imagine you want to fetch some data to show on the page. Oh, and you want to show a loading spinner when the request starts, and hide it when the request completes. When something goes wrong, you show an error message instead. const fetchAndDisplay =
Introduction The async/await syntax in JavaScript ES7 makes it easier to coordinate asynchronous promises. If you need to asynchronously fetch data from multiple databases or APIs in a certain order, you can end up with a spaghetti of promises and callbacks. The async/await construct allows us to express such logic more succinctly with more readable and maintainable code. This tutorial explains Ja
Compared to using promises directly, not only can async and await make code more readable for developers — they enable some interesting optimizations in JavaScript engines, too! This write-up is about one such optimization involving stack traces for asynchronous code. The fundamental difference between await and vanilla promises is that await X() suspends execution of the current function, while p
The original GitHub issue for "Aborting a fetch" was opened in 2015. Now, if I take 2015 away from 2017 (the current year), I get 2. This demonstrates a bug in maths, because 2015 was in fact "forever" ago. 2015 was when we first started exploring aborting ongoing fetches, and after 780 GitHub comments, a couple of false starts, and 5 pull requests, we finally have abortable fetch landing in brows
In this guide you will learn how to use Node’s util.promisify to promisify your own functions. This utility function was included in NodeJS version 8. If you plan to follow along with this guide you’ll need to install the latest version. As an added bonus I also show you how to use promisify with await and async.
Finally the Promise.prototype.finally() is available Serg Hospodarets Blog Since the Promises were added in JavaScript, one of the biggest concerns was the absence of an ability to easily apply some code after the Promise is fulfilled (after both success and reject actions). There are many examples of such a need: showing a loader when the request to the server is in flight or even a simpler case-
In Promise-based code, there are usually many callbacks, each one having a separate scope for variables. What if you want to share data between those callbacks? This blog post describes techniques for doing so. The problem # The following code illustrates a common problem with Promise callbacks: The variable connection (line A) exists in one scope, but needs to be accessed in other scopes (line B
Update 2017-08-12: I added an FAQ. The proposal “Promise.try()” by Jordan Harband is currently at stage 1. This blog post explains how it works. Promise.try() # To understand what Promise.try() does, consider the following code: function countPlusOneAsync() { return countAsync() .then(result => { return result + 1; }); } If countAsync() throws a synchronous exception then so does countPlusOneAsyn
Intro XHR から fetch() に積極的に移行しづらかった最大のミッシングピースとして、中断できないという問題があった。 これは、 fetch() が選んだ Promise ベースのインタフェースにおいて、キャンセルをどうするかという議論と絡み、長く決着が付かずにいた問題である。 最近、やっと話が前進したので、ここまでの経過を解説する。 Fetch のミッシングピース fetch() は、ブラウザが発行するリクエストと、取得するレスポンスを扱う低レベルなインタフェースとして策定が始まった。 DOM の API が Promise ベースに移行しつつある流れを汲み、 fetch() もまた Promise を返す関数一発スタイルになった。 クラスからインスタンスを生成しメソッドを呼ぶ XHR スタイルでは、インスタンスを再利用した場合の挙動などを含め、オブジェクトのライフサイクルを
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く