You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
variPr=Promise.resolve("hello").then((res)=>{letval="wow !";console.log(`then I receive [${res}], and return [${val}]`);returnval;})// stop promise:.then((res)=>Promise.stop())// never get call:.then((res)=>console.log("then II: ",res));// sometime later...setTimeout(()=>{iPr.then(Promise.regain((res)=>{// give me stopped valuesconsole.log(`promise is recovered, \nand get stopped values: [${res}]`);}));},1e3);
受到 Promise.stop 灵感启发, 既然能 "停止" 为何不来试试 "恢复", 以及 "恢复" 时可拿到停止的返回值.
作为技术实现上探讨, 在业务应用上, 可各自脑洞.
停止/恢复 方法:
Promise.stop()
Promise.regain()
停止示例:
恢复示例:
如下为实现:
完整示例:
further reading: #xieranmaya/blog#5
The text was updated successfully, but these errors were encountered: