You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert
Node.js 8 has a new utility function: util.promisify(). It converts a callback-based function to a Promise-based one. util.promisify() in action # If you hand the path of a file to the following script, it prints its contents. // echo.js const {promisify} = require('util'); const fs = require('fs'); const readFileAsync = promisify(fs.readFile); // (A) const filePath = process.argv[2]; readFileAsy
Node.js のコアに util.promisify が追加された。 github.com 今回は util.promisify が持つ役割を中心に Node.js における Promise の立場についても話していけるといいと思う。 util.promisify とは 読んで字のごとく関数を Promise に変換してくれるユーティリティメソッド。 下記のような要領で変換できる。 const util = require('util'); const fs = require('fs'); const stat = util.promisify(fs.stat); stat('.').then((stats) => { console.log(stats); }).catch((error) => { console.error(error); }); async-awaitを使いたい
In this course we will learn how to use the ES2017 async and await keywords to write asynchronous code that is more readable and easier to follow than equivalent code based on long promise chains or deeply nested callbacks. The await operator takes a promise and then pauses the function execution until that promise is settled which allows for an async function to read like sequential synchronous c
Over the years there has been an increase in the popularity of promises in Node.js and JavaScript in general. This popularity is evidenced by the Promise object becoming part of the ECMAScript specification. As a result of having promises built-in, the language can add new capabilities that rely on them. Async functions are a prime example of a new language feature that uses promises. One reason f
A clear and consistent approach to cancelling asynchronous operations: Asynchronous functions or iterators Fetching remote resources (HTTP, I/O, etc.) Interacting with background tasks (Web Workers, forked processes, etc.) Long-running operations (animations, etc.) A general-purpose coordination mechanism with many use cases: Synchronous observation (e.g. in a game loop) Asynchronous observation (
Node.js 6.6.0 added a sporadically useful bug/feature: logging unhandled promise rejections to the console by default. In other words, the below script will print an error to the console: Promise.reject(new Error('woops')); /* Output: $ node test.js (node:7741) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: woops (node:7741) DeprecationWarning: Unhandled pr
はじめに AigleというPromiseライブラリを開発しています。このライブラリはベンチマーク上だけでなく実際の本番環境を考慮した高速化を実現しています。 今回はその過程でBluebirdに大変お世話になったので、なぜBluebirdが速いのか、そしてなぜAigleが速いのかついて説明したいと思います。 基本的なPromiseの知識 まず本題に入る前にPromiseの基本的なことを説明しておきます。 Promiseにはpending, fulfilled, rejectedの3つの状態があります。一度pendingから別の状態に変わった場合は、そのPromiseの状態が変わることはありません。 (引用: MDN) またPromiseは非同期であることが保証されています。この事は少し重要なので触れておきます。
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く