Neoclassic Placebo Maker

    miniprogram-cancel-token
    TypeScript icon, indicating that this package has built-in type declarations

    5.1.2 • Public • Published

    miniprogram-cancel-token npm version

    Cancle Token for Promise in MiniProgram

    APT

    CancelTokenSource 外部调用(暴露出的API接口)

    • cancel(reason?) 取消操作
    • token 调用cancel时所取消的 CancelToken

    CancelToken 响应cancel操作(API内部实现)

    • #source() 静态方法创建一个CancelTokenSource
    • promise 调用cancel时所触发的promise;
    • isCancelled() 判断是否已经取消过;
    • throwIfRequested() 取消则抛出异常;

    usage

    function doFoo(foo, cancelToken) {
        return new Promise((resolve, reject) => {
          cancelToken.throwIfRequested();
          cancelToken.promise.then(()=>{
              // do somethig to cancel
              // like xhr.abort()
              foo.abort();
          })
          resolve('something');
      });
    }
    import CancelToken from 'miniprogram-cancel-token'
    //create CancelToken Source
    const cts = CancelToken.scoure();
    //use canceltoken
    doFoo(foo,stc.token).then(console.log);
    // cancle it
    cts.cancel();
     

    references

    Keywords

    none

    Install

    npm i miniprogram-cancel-token

    DownloadsWeekly Downloads

    35

    Version

    5.1.2

    License

    Apache-2.0

    Unpacked Size

    22.4 kB

    Total Files

    11

    Last publish

    Collaborators

    • newfuture