59 lines
1.4 KiB
JavaScript
59 lines
1.4 KiB
JavaScript
(function(){
|
|
class LNPromise
|
|
{
|
|
constructor(executor, label){
|
|
this.promise = new Promise(
|
|
(resolve,reject) => {
|
|
this.resolve = (v) => {
|
|
this._s.state = "ready";
|
|
resolve(v);
|
|
this.release();
|
|
},
|
|
this.reject = (e) => {
|
|
this._s.state = "failed";
|
|
reject(e);
|
|
this.release();
|
|
}
|
|
executor && executor(
|
|
this.resolve,
|
|
this.reject
|
|
);
|
|
}
|
|
);
|
|
|
|
if (!label)
|
|
label = "N.D.";
|
|
|
|
this._s = {
|
|
label,
|
|
state: "waiting"
|
|
};
|
|
|
|
this.idx = LN.$unique();
|
|
LNPromise.$current[this.idx] = this._s;
|
|
}
|
|
|
|
label(){
|
|
return this._s.label;
|
|
}
|
|
|
|
state(){
|
|
return this._s.state;
|
|
}
|
|
|
|
release(){
|
|
setTimeout(()=>{
|
|
Vue.delete(LNPromise.$current, this.idx);
|
|
},1000);
|
|
}
|
|
|
|
then(){
|
|
return this.promise.then.apply(this.promise, arguments);
|
|
}
|
|
|
|
static getCurrentPromises(){ return LNPromise.$current; }
|
|
}
|
|
LNPromise.$current = {};
|
|
|
|
LN.$add("LN.Promise",LNPromise);
|
|
})(); |