Created
June 20, 2012 18:19
-
-
Save bryanforbes/2961380 to your computer and use it in GitHub Desktop.
Deferred adapter for node
This file contains hidden or 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
define([ | |
"dojo/Deferred" | |
], function(Deferred){ | |
var slice = Array.prototype.slice; | |
return function adapt(func){ | |
var args = slice.call(arguments, 1), | |
def = new Deferred; | |
args.push(function(err, value){ | |
if(err){ | |
def.reject(err); | |
}else{ | |
def.resolve(value); | |
} | |
}); | |
func.apply(null, args); | |
return def.promise; | |
}; | |
}); |
This file contains hidden or 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([ | |
"adapt", | |
"dojo/node!fs" | |
], function(adapt, fs){ | |
var readdir = adapt.bind(null, fs.readdir); | |
readdir("./foo").then(function(files){ | |
console.log(files); | |
}, function(err){ | |
console.error(err); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment