Skip to content

Commit

Permalink
Add a simple example demonstrating ticks and calls.
Browse files Browse the repository at this point in the history
David Tudury authored and domenic committed Sep 22, 2013

Unverified

This user has not yet uploaded their public signing key.
1 parent dc92d37 commit 0b4aa3f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions examples/simple-calls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";

var Q = require("../q");

function log() {
console.log.apply(console, arguments);
}

Q("----------- tick 1 -----------").done(log); // next tick
Q().thenResolve("----------- tick 2 -----------").done(log); // in 2 ticks
Q().thenResolve().thenResolve("----------- tick 3 -----------").done(log); // in 3 ticks


Q(1).then(log).done(); //logs "1"

Q().thenResolve(2).done(log); //logs "2"

Q(5).then(Q.fbind(log, 3, 4)).done(); //logs "3 4 5"

Q(log).fapply([6, 7, 8]).done(); //logs "6 7 8"

Q(log).fcall(9, 10, 11).done(); //logs "9 10 11"

Q.try(log, 12, 13).done(); //logs "12, 13" (same as fcall)


log("----------- tick 0 -----------"); //called this tick

0 comments on commit 0b4aa3f

Please sign in to comment.