Created
February 4, 2010 02:34
-
-
Save creationix/294304 to your computer and use it in GitHub Desktop.
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
From 151330d050405d088b357713d7c204847902be37 Mon Sep 17 00:00:00 2001 | |
From: Tim Caswell <[email protected]> | |
Date: Wed, 3 Feb 2010 20:29:13 -0600 | |
Subject: [PATCH] Bind the addCallback function on File.read and File.write so we can use it in any context. | |
--- | |
lib/file.js | 19 ++++++++++++++++--- | |
1 files changed, 16 insertions(+), 3 deletions(-) | |
diff --git a/lib/file.js b/lib/file.js | |
index 1dc2704..843f3fb 100644 | |
--- a/lib/file.js | |
+++ b/lib/file.js | |
@@ -17,10 +17,19 @@ function debugObject (obj) { | |
} | |
} | |
-exports.read = posix.cat; | |
+exports.read = function () { | |
+ var promise = posix.cat.apply(null, arguments), | |
+ addCallback = promise.addCallback; | |
+ // Bind addCallback to the promise. | |
+ promise.addCallback = function () { | |
+ return addCallback.apply(promise, arguments); | |
+ }; | |
+ return promise; | |
+}; | |
exports.write = function (filename, data, encoding) { | |
- var promise = new events.Promise(); | |
+ var promise = new events.Promise(), | |
+ addCallback = promise.addCallback; | |
encoding = encoding || "utf8"; // default to utf8 | |
@@ -47,6 +56,10 @@ exports.write = function (filename, data, encoding) { | |
promise.emitError(); | |
}); | |
+ // Bind addCallback to the promise. | |
+ promise.addCallback = function () { | |
+ return addCallback.apply(promise, arguments); | |
+ }; | |
return promise; | |
}; | |
@@ -73,7 +86,7 @@ var proto = exports.File.prototype; | |
proto._maybeDispatch = function () { | |
var self, args, method, promise, userPromise; | |
- | |
+ | |
self = this; | |
if (self.currentAction) { return; } | |
-- | |
1.6.5.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment