On Github revathskumar / keralajs-promises
promise.then(onFulfilled, onRejected)
User.get(1,{ success: function(){ console.log('Success'); }, error: function(){ console.log('Error'); } })
User.get(1).then( function(){ console.log('Success'); }, function(){ console.log('Error'); } );
User.get('1', { success: function(){ Accounts.get('1', { success: function(){ Accounts.update({twitter: @addyosmani}, { success: fucntion(){ console.log('Success') }, error: function(){ console.log('Error'); } }) }, error: fucntion(){ console.log('Error'); } }) }, error: function(){ console.log('error'); } });
User.get(1) .then(Accounts.get) .then(function(){ return Accounts.update({twitter: @addyosmani}) }) .then(function(){ console.log('Success'); }) .then(undefined, function(){ console.log('Error'); });
var User = (function(){ function get(user_id){ var promise = new Aplus(); $.get('/users/' + user_id, { success: function(data){ promise.fulfill(data.account_id); }, error: function(){ promise.reject('Error'); } }); return promise; } return { get: get } })
Aplus.pool( asyncFunc(), anotherAsyncFunc() ) .then(asyncSuccess, asyncError);
$.when( $.ajax( "/page1.php" ), $.ajax( "/page2.php" ), ) .then(onSuccess, onError);
$.when(function(){ console.log('Hello Promise'); }) .then(function(){ console.log('Success1'); }, function(){ console.log('Error1'); }) .then(function(){ console.log('Success2'); }, function(){ console.log('Error2'); });