Promise 异步函数的加上外壳终止Promise

//promise异步函数的请求终止
export default function markCancleble(promise){
let hasCanceled_ = false ;
const wrappedPromise = new Promise((resolve,reject)=>{
// 传递过来的promise
promise.then((val)=>{
hasCanceled_?reject({isCanceled:true}):resolve(val)
})
promise.catch((err)=>{
hasCanceled_?reject({isCanceled:true}):resolve(err)
})
return {
promise:wrappedPromise,
cancle(){
hasCanceled_=true
}
}
})
} //useful 挂载到this中
this.cancleble = markCancleble (fetch())
this.cancleble.promise
.then()
.catch()
///
//取消
this.cancleble.cancle()
上一篇:性能测试报告的指标选择、数据选择和分析的参考【以Apache AB test为例】


下一篇:Connector