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
Ever since the dawn of Node.js, Node developers have complained about Callback Hell. Various solutions have been proposed with various degrees of success. Generators is an exciting prospect because it finally allows us to write async code in a straight-line fashion. Although generators is not yet available on all browsers, you can make it work using the Babel compiler. It is getting more adoption
react-router@1.0.0-rc3を使っていると、onEnterでStoreを更新して、終わってからRouteへ移動したい。Angularで言うui-routerのresolveが欲しいと思っていました。 EventEmitterを継承して.emitをオーバーライドすれば対応可能です。軽くテストを通したライブラリも公開しています。1 具体的には下記のように実装します。 // Dependencies import {EventEmitter} from 'events' // Public class AsyncEmitter extends EventEmitter{ emit(event,...args){ let promises= [] this.listeners(event).forEach(listener=>{ promises.push(listener(...
Cancellation overhaul Cancellation has been redesigned for bluebird 3.0. Any code that relies on 2.x cancellation semantics won't work in 3.0 or later. See Cancellation for more information. Promisification API changes Both promisification (Promise.promisify and Promise.promisifyAll) methods and Promise.fromCallback now by default ignore multiple arguments passed to the callback adapter and instea
W’ve seen that Futures/Promises emerge as a logical meaning for asynchronous functions like in this Node example : fs.readFile(‘…’) // => a Future/PromiseSimilarly, we w’d like to represent the meaning of functions like this someEventSource.on('event', ...) // => ?The second code shares the asynchronous semantics of the first, hence the use of callbacks in both cases. But instead of a single futur
自作RustスタイルECMAScript用Option型ライブラリoption-tをいろいろアップデートしたので、リリースノートがてら書く。ご存知ない方はこちらをどうぞ。要はOption<T>/Maybe型だ。 Promiseへのキャストメソッドを用意した ECMA 262の文化には、すでにMaybeもどきの標準仕様が存在する。ご存知Promiseだ。 だが、Promiseは非同期前提の操作になるので、同期的に実行するAPI群との親和性が良いとは言えず、かといって全てをPromiseにするほどでもない場合のために、わざわざこんなライブラリを作ったというのは前に書いた通り。 でも、今の世の中、どこかしらの関数がPromiseを返すじゃん?そこに上手く混ぜられるととっても楽じゃん? てなわけでcast用メソッドとしてOptionT.asPromise()を追加した。これにより、スムーズにPro
RQ: Better Living Through Asynchronicity Douglas Crockford 2017-09-20 RQ is a small JavaScript library for managing asynchronicity in server applications. The source is available at https://github.com/douglascrockford/RQ. This page is available at http://RQ.crockford.com/. It is in the Public Domain. Asynchronicity Asynchronicity is becoming the preferred method for solving a large class of proble
github.com README すらまだ書いてないけど、とりあえず使えるものができたので npm にだけ登録してみた。 追記 javascripter.hatenablog.com 3 秒で不要になった。 Promise を直列で実行するのに、 Promise それ自身の特徴を使えば簡単にできることに気付かなかった。 reduce を reduce としてしかみてなく本質をみれば気付けたのに気付けなかったので修行足りてない。 何をするライブラリを作ったのか 簡単に言えば Promise を返す関数を順序を守って実行するものである。まぁ queue をためて前の関数の実行が終わったら次の関数を実行する、といったようなもの。 何故必要だったのか、あるいは作ったモチベーション 仕事をしていて AngularJS を使っているんだけど、 $http サービスの返す Promise をキャッシュ
動機 初期状態で未選択なラジオボタンがあるようなフォームを作っている場合、ラジオボタンに対応するモデルの値を「この値は未選択である」というのをJSで表現するのは結構面倒くさい。チェックボックスであれば, booleanのどちらかで状態が確定するが、ラジオボタンだと取りうる値は複数になるし、初期状態で選択されているか否かの問題が発生する。選択されていない状態を専用にフラグとして持つのは気持ち悪いが、かといって、未選択の状態を-1や9999ないしnull、undefinedで表現するのは危うい。コードを書いた本人しかわからない。 RustやScalaなどのようにOption<T>/Maybeがある言語なら、こんなまどろっこしい思いはせずに、明示的に値の有無を表現できる。 というわけで、ないなら作ってしまえば良いじゃないメソッドで作った。 Option<T>型について 私が説明するよりもわかりや
と、いうのを作りました。 node.jsの非同期APIはコールバックでエラーと結果を受け取りますが、それをPromiseベースのAPIに変換します。 こうやって使う。 var fs = require("fs"); var prominence = require("prominence"); // prominence するとそのオブジェクトで使える全メソッドが Promise 仕様になる prominence(fs).readFile("hoge.txt", "utf-8").then(function(text) { console.log(text); }).catch(console.error.bind(console)); // こういう書き方もできる prominence(fs, "readFile", [ "hoge.txt", "utf-8" ]).then(funct
JavaScript Advent Calendar 2014 11日目。 いきなり要約: Promiseや非同期テストのアサーションを簡単確実に書けるようになるesplanというライブラリのPoCを作った話。 Promiseや非同期のテストは難しい 詳しくはJavaScript Promiseの本: Chapter.3 Promiseのテストをご覧いただきたいのだが、Promiseのテストを正確に書くのはそんなに簡単ではない。 例えばmochaだと、 // 間違ったテスト1: // mayBeResolveWithOne() が1以外でresolveしたときタイムアウトエラーになる it("mayBeResolveWithOne()は1でresolveする", function(done) { mayBeResolveWithOne().then(function(value) { as
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く