Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Eugene Shen
jio
Commits
2ac95e1d
Commit
2ac95e1d
authored
11 years ago
by
Tristan Cavelier
Browse files
Options
Download
Email Patches
Plain Diff
Promise.js success static method added
parent
083f8f7a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
0 deletions
+26
-0
src/jio/core/Promise.js
src/jio/core/Promise.js
+26
-0
No files found.
src/jio/core/Promise.js
View file @
2ac95e1d
...
...
@@ -75,6 +75,32 @@ Promise.error = function (item, onError) {
return
p
;
};
/**
* success(item, [onSuccess]): Promise
*
* Return an item as first parameter of the promise answer. The method returns a
* resolved promise.
*
* Promise.success(errorPromise).then(console.log); // shows 'Error'
* Promise.success(Promise.error('a')).then(console.log); // shows 'a'
*
* @method success
* @static
* @param {Any} item The item to use
* @param {Function} [onSuccess] the callback called on success
* @return {Promise} The promise
*/
Promise
.
success
=
function
(
item
,
onSuccess
)
{
var
p
=
new
Promise
().
done
(
onSuccess
),
solver
=
p
.
defer
();
Promise
.
when
(
item
,
solver
.
resolve
.
bind
(
solver
),
solver
.
resolve
.
bind
(
solver
),
solver
.
notify
.
bind
(
solver
)
);
return
p
;
};
////////////////////////////////////////////////////////////
// http://wiki.commonjs.org/wiki/Promises/B
// get(object, name)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment