This file contains 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
function isGenerator(val) { | |
return Object.prototype.toString.call(val) === "[object Generator]"; | |
} | |
var PENDING = {}; | |
function run(fn, args, idx) { | |
var cb = args[idx], | |
g; |
This file contains 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
require('colors'); | |
function* genFibo() { | |
var f1 = 0, f2 = 1; | |
while (true) { | |
console.log(("genFibo loop: " + f1).green) | |
yield f1; | |
var f = f1 + f2; | |
f1 = f2; | |
f2 = f; |
This file contains 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
{ | |
"targets": [ | |
{ | |
"conditions": [ | |
["OS=='mac'", { | |
"xcode_settings": { | |
"GCC_ENABLE_CPP_EXCEPTIONS": "YES" | |
} | |
}], | |
], |
This file contains 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
//fibers | |
function markComplete(postedItems, completionCallback) { | |
var errors = []; | |
var getItemToUpdate = function(item) { | |
var fiber = Fiber.current; | |
process.nextTick(function() { | |
client.queryEntity('tasks', 'partition1', item, function(err, task) { | |
fiber.run(task); | |
}); |
This file contains 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
var galaxy = require('galaxy'); | |
function *waitForOne(futures) { | |
return yield galaxy.star(function(cb) { | |
for (var i = 0; i < futures.length; i++) { | |
galaxy.unstar(futures[i], 0)(function(e, r) { | |
if (cb) cb(e, r); | |
cb = null; | |
}); | |
} |
This file contains 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
"use strict"; | |
function millis(hr) { | |
return hr[0] * 1000 + Math.floor(hr[1] / 1000000); | |
} | |
function busyWait(ms, cb) { | |
var hr0 = process.hrtime(); | |
while (millis(process.hrtime(hr0)) < ms); | |
var elapsed = millis(process.hrtime(hr0)); |
This file contains 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
var Fiber = require("./build/Release/fibers").Fiber; | |
function wrap(fn, idx) { | |
function F() { | |
var cb = arguments[idx]; | |
var that = this, | |
args = arguments; | |
Fiber(function () { | |
var val, err = null; |
This file contains 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
"use strict"; | |
exports.queryAll = function(conn, sql, args, cb) { | |
var allRows = []; | |
conn.execute(sql, args, { | |
resultSet: true | |
}, function(err, result) { | |
if (err) return cb(err); | |
function fetch() { |
This file contains 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
var oracledb = require('oracledb'); | |
var ez = require('ez-streams'); | |
var cnx = oracledb.getConnection({ | |
user: "scott", | |
password: "oracle", | |
connectString: "localhost/ORCL", | |
}, _); | |
try { |
This file contains 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
"use strict"; | |
function assert(i, j) { | |
if (i !== j) throw new Error("expected " + i + ", got " + j) | |
} | |
function callbackIter(fn, n, cb) { | |
var t0 = Date.now(); | |
(function doIt(i) { | |
if (i < n) fn(i, function(err, val) { |