Skip to content

Instantly share code, notes, and snippets.

View kriszyp's full-sized avatar
💭
Working on @HarperDB

Kris Zyp kriszyp

💭
Working on @HarperDB
View GitHub Profile
require("sys").puts("a is loaded");
throw new Error("some error");
require.paths.push(".");
exports.test = {
get foo(){
require("c");
}
};
require("a"); // a is just empty
var promise = new process.Promise();
promise.then(function(){
require("sys").puts("done");
});
promise.emit("success");
exports.name = "test";
require.paths.push("../folder2");
require("b");
var posix = require("posix");
var print = require("sys").puts;
var j = 0;
for(var i = 0;i < 100; i++){
posix.stat("file" + i, process.O_RDONLY, 0666) // these files don't exist
.addErrback(function(e){
j++; // only makes it to about 17
print(j);
})
.addCallback(function(){
var posix = require("posix");
var print = require("sys").puts;
var j = 0;
for(var i = 0;i < 3; i++){
findFile(i);
}
function findFile(i){
posix.stat("file" + i, process.O_RDONLY, 0666) // these files don't exist
.addErrback(function(e){
j++; // only makes it to about 17
/**
* Takes an array of promises and returns a promise that that is fulfilled once all
* the promises in the array are fulfilled
* @param group The array of promises
* @return the promise that is fulfilled when all the array is fulfilled
*/exports.group = function(group){
var deferred = defer(); // this function is assigned process.Promise
if(!(group instanceof Array)){
group = Array.prototype.slice.call(arguments);
}
var setTimeout = require("browser/timeout").setTimeout;
var deferred = require("promise").defer();
var queue = require("event-queue");
deferred.promise.then(function(){
print("done");
});
setTimeout(function(){
deferred.resolve(10);
queue.shutdown();
}, 500);