Last active
June 16, 2016 13:26
-
-
Save nazrdogan/9f6604b4c5198c47f652ea72d9999938 to your computer and use it in GitHub Desktop.
Titanium + Q 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
var Q = require("q"); | |
function Promise(name) { | |
var defer = Q.defer(); | |
setTimeout(function() { | |
defer.notify('About to greet ' + name + '.'); | |
if (name) { | |
defer.resolve('Hello, ' + name + '!'); | |
} else { | |
defer.reject('Greeting ' + name + ' is not allowed.'); | |
} | |
}, 1000); | |
return defer.promise; | |
} | |
var rob = Promise("Rob"); | |
rob.then(function(greeting) { | |
alert('Success: ' + greeting); | |
}, function(reason) { | |
alert('Failed: ' + reason); | |
}, function(update) { | |
alert('Got notification: ' + update); | |
}); | |
function promisedStep1() { | |
return "pro1"; | |
} | |
function promisedStep2() { | |
return "pro2"; | |
} | |
function promisedStep3() { | |
return "pro3"; | |
} | |
function promisedStep4() { | |
return "pro4"; | |
} | |
function doneFunc() { | |
Ti.API.info("Value"); | |
} | |
Q.fcall(promisedStep1).then(promisedStep2).then(promisedStep3).then(promisedStep4).then(function(value4) { | |
Ti.API.info(value4); | |
}).catch(function(error) { | |
}).done(doneFunc()); | |
$.index.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment