Skip to content

Instantly share code, notes, and snippets.

@foo9
Created May 1, 2015 01:18
Show Gist options
  • Save foo9/69952aa7b20d2618886c to your computer and use it in GitHub Desktop.
Save foo9/69952aa7b20d2618886c to your computer and use it in GitHub Desktop.
var promise = new Promise(function(resolve, reject) {
if ( /* 何らかの非同期処理 */ ) {
resolve(); // 成功
} else {
reject(); // 失敗
}
});
promise.then(function(result) {
// 成功
console.log(result);
}, function(error) {
// 失敗
console.log(error);
});
promise.then(function(result) {
// 成功
console.log(result);
}).catch(function(error) {
// エラーのとき
console.log(error);
});
// Promise.resolve
// Promise.reject
// Promise.all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment