-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds .success() and .fail() to ChainFind (#316)
This is just an initial code, we should improve in the future and make more parts of the code use the "Promise" (like Model.get)
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
exports.Promise = Promise; | ||
|
||
function Promise(opts) { | ||
opts = opts || {}; | ||
|
||
var success_cb = opts.success || null; | ||
var fail_cb = opts.fail || null; | ||
|
||
return { | ||
handle: function (promise) { | ||
promise(function (err) { | ||
if (err) { | ||
if (fail_cb) fail_cb(err); | ||
} else { | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
|
||
if (success_cb) success_cb.apply(null, args); | ||
} | ||
}); | ||
}, | ||
success: function (cb) { | ||
success_cb = cb; | ||
return this; | ||
}, | ||
fail: function (cb) { | ||
fail_cb = cb; | ||
return this; | ||
} | ||
}; | ||
} |
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