Last active
August 19, 2020 05:48
-
-
Save thomasJang/ebef17c4fb31f450a8ac5b1705eb2589 to your computer and use it in GitHub Desktop.
asyncPromise.js
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
axisj.promise = function () { | |
// 프라미스 | |
var myClass = function () { | |
this.busy = false; | |
this.queue = []; | |
this.then = function (fn) { | |
this.queue.push(fn); | |
this.exec(); | |
return this; | |
}; | |
// 함수 실행자 (큐가 남아 있으면 실행합니다.) | |
this.exec = function (data) { | |
if (this.busy) return this; // 바쁘니까 다음에 다시 봅시다. | |
var Q = this.queue.shift(), | |
self = this; | |
if (Q) { | |
this.busy = true; | |
try { | |
// 큐에 함수를 실행 인자는 ok, err, data 로 | |
Q( | |
function (a) { | |
self.busy = false; | |
self.exec(a); | |
}, | |
function (e) { | |
self._catch(e); | |
}, | |
data | |
); | |
} | |
catch (e) { | |
this._catch(e); | |
} | |
} else { | |
this.busy = false; | |
} | |
}; | |
// 에러가 발생되면.. 호출 하려고 둠. | |
this.catch = function (fn) { | |
this._catch = fn; | |
}; | |
}; | |
// 클래스 인스턴스를 반환합니다. | |
return new myClass(); | |
} |
TypeError: Cannot find function _catch in object [object Object].
LineNuber : 35
How to define it?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.