• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript types.isCancelled函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中common/types.isCancelled函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isCancelled函数的具体用法?TypeScript isCancelled怎么用?TypeScript isCancelled使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了isCancelled函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1:

 .catch(e => {
   if (isCancelled(e)) {
     cancelledSecondTask = true;
   } else {
     throw e;
   }
 });
开发者ID:itchio,项目名称:itch,代码行数:7,代码来源:index.spec.ts


示例2: getClient

export async function call<Params, Res>(
  store: Store,
  logger: Logger,
  rc: RequestCreator<Params, Res>,
  params: Params,
  setup?: SetupFunc
): Promise<Res> {
  const client = await getClient(store, logger);

  try {
    logger.debug(`🙏 ${rc({} as any)(client).method}`);
    return await client.call(rc, params, setup);
  } catch (e) {
    if (isCancelled(e)) {
      // nvm
    } else if (isAborted(e)) {
      // nvm
    } else {
      logger.error(`Caught butler error:`);
      if (isInternalError(e)) {
        const ed = getRpcErrorData(e);
        if (ed) {
          logger.error(`butler version: ${ed.butlerVersion}`);
          logger.error(`Golang stack:\n${ed.stack}`);
        }
        logger.error(`JavaScript stack: ${e.stack}`);
      } else {
        logger.error(`${e.message}`);
      }
    }
    throw e;
  }
}
开发者ID:itchio,项目名称:itch,代码行数:33,代码来源:utils.ts


示例3: err

function err(e: Error, action: IAction<any>) {
  if (isCancelled(e)) {
    console.warn(`reactor for ${action.type} was cancelled`);
  } else {
    printError(
      `while reacting to ${(action || { type: "?" }).type}: ${e.stack || e}`
    );
  }
}
开发者ID:HorrerGames,项目名称:itch,代码行数:9,代码来源:route.ts


示例4: err

function err(logger: Logger, e: Error, action: Action<any>) {
  if (isCancelled(e)) {
    console.warn(`reactor for ${action.type} was cancelled`);
  } else {
    const actionName = (action || { type: "?" }).type;
    const errorStack = e.stack || e;
    const msg = `while reacting to ${actionName}: ${errorStack}`;
    logger.error(msg);
  }
}
开发者ID:itchio,项目名称:itch,代码行数:10,代码来源:route.ts


示例5: return

  return (e: Error) => {
    if (isNetworkError(e)) {
      logger.warn(`Uncaught network error: ${e.stack}`);
      return;
    }

    if (isCancelled(e)) {
      logger.info(`Something was cancelled: ${e.stack}`);
      return;
    }

    handle(type, e)
      .catch(e2 => {
        // well, we tried.
        logger.error(`Error in crash-reporter (${type})\n${e2.stack}`);
      })
      .then(() => {
        if (type === ErrorType.UncaughtException) {
          exit(1);
        }
      });
  };
开发者ID:itchio,项目名称:itch,代码行数:22,代码来源:crash-reporter.ts


示例6: asTask

async function asTask(opts: IAsTaskOpts) {
  const id = uuid();

  const { store, name, gameId } = opts;

  const memlog = new memory.WritableStream();
  const logger = makeLogger({ customOut: memlog });

  store.dispatch(
    actions.taskStarted({
      id,
      name,
      gameId,
      startedAt: Date.now(),
    })
  );

  const ctx = new Context(store);
  ctx.registerTaskId(id);
  ctx.on("progress", (ev: IProgressInfo) => {
    store.dispatch(actions.taskProgress({ id, ...ev }));
  });

  getCurrentTasks()[id] = ctx;

  let err: Error;

  const { work, onError, onCancel } = opts;

  try {
    await work(ctx, logger);
  } catch (e) {
    err = e;
  }

  delete getCurrentTasks()[id];
  try {
    logger.close();
  } catch (e) {
    rootLogger.warn(`Couldn't close logger: ${e.stack}`);
  }

  if (err) {
    if (isCancelled(err)) {
      rootLogger.warn(`Task ${name} cancelled`);
      if (onCancel) {
        await onCancel();
      }
    } else if (isAborted(err)) {
      rootLogger.warn(`Task ${name} aborted`);
      if (onCancel) {
        await onCancel();
      }
    } else {
      rootLogger.warn(`Task ${name} threw: ${err.stack}`);
      if (onError) {
        await onError(err, memlog ? memlog.toString() : "(No log)");
      }
    }
  }

  store.dispatch(
    actions.taskEnded({
      id,
      err: err ? `${err}` : null,
    })
  );
}
开发者ID:HorrerGames,项目名称:itch,代码行数:68,代码来源:as-task.ts


示例7: driverPoll

async function driverPoll(store: Store) {
  logger.debug(`Download driver polling...`);

  const rs = store.getState();
  if (!rs.setup.done) {
    return;
  }

  const { paused } = rs.downloads;
  if (paused) {
    logger.debug(`Paused... current phase: ${Phase[state.getPhase()]}`);
    switch (state.getPhase()) {
      case Phase.RUNNING: {
        await state.cancel();
        break;
      }
    }
  } else {
    logger.debug(`Not paused... current phase: ${Phase[state.getPhase()]}`);
    switch (state.getPhase()) {
      case Phase.IDLE: {
        state.setPhase(Phase.STARTING);
        let driveConvo: Conversation;
        try {
          await mcall(messages.DownloadsDrive, {}, convo => {
            hookLogging(convo, logger);
            state.registerConvo(convo);
            driveConvo = convo;

            convo.on(messages.DownloadsDriveStarted, async ({ download }) => {
              await refreshDownloads(store);
            });

            convo.on(messages.DownloadsDriveDiscarded, async ({ download }) => {
              await refreshDownloads(store);
            });

            convo.on(messages.DownloadsDriveErrored, async ({ download }) => {
              await refreshDownloads(store);
            });

            convo.on(messages.DownloadsDriveFinished, async ({ download }) => {
              await refreshDownloads(store);
              store.dispatch(actions.downloadEnded({ download }));
            });

            convo.on(
              messages.DownloadsDriveProgress,
              async ({ download, progress, speedHistory }) => {
                store.dispatch(
                  actions.downloadProgress({
                    download,
                    progress,
                    speedHistory,
                  })
                );
              }
            );
          });
        } catch (e) {
          if (isCancelled(e)) {
            // ignore
          } else {
            logger.error(`${e.stack}`);
          }
        } finally {
          if (state.isConvoCurrent(driveConvo)) {
            state.setPhase(Phase.IDLE);
            logger.debug(`Going back to idle after Downloads.Drive call`);
          } else {
            logger.debug(
              `A Downloads.Drive call finished, but another is already up.`
            );
          }
        }

        break;
      }
    }
  }
}
开发者ID:itchio,项目名称:itch,代码行数:81,代码来源:driver.ts


示例8: asTask

async function asTask(opts: AsTaskOpts) {
  const id = uuid();

  const { store, name, gameId, caveId } = opts;

  const logger = recordingLogger(mainLogger);

  store.dispatch(
    actions.taskStarted({
      id,
      name,
      gameId,
      caveId,
      startedAt: Date.now(),
    })
  );

  const ctx = new Context(store);
  ctx.registerTaskId(id);
  ctx.on("progress", (ev: ProgressInfo) => {
    store.dispatch(actions.taskProgress({ id, ...ev }));
  });

  getCurrentTasks()[id] = ctx;

  let err: Error;

  const { work, onError, onCancel } = opts;

  try {
    await work(ctx, logger);
  } catch (e) {
    err = e;
  }

  delete getCurrentTasks()[id];

  if (err) {
    if (isCancelled(err)) {
      mainLogger.warn(`Task ${name} cancelled`);
      if (onCancel) {
        await onCancel();
      }
    } else if (isAborted(err)) {
      mainLogger.warn(`Task ${name} aborted`);
      if (onCancel) {
        await onCancel();
      }
    } else {
      mainLogger.warn(`Task ${name} threw: ${err.stack}`);
      if (onError) {
        await onError(err, logger.getLog());
      }
    }
  }

  store.dispatch(
    actions.taskEnded({
      id,
      err: err ? `${err}` : null,
    })
  );
}
开发者ID:itchio,项目名称:itch,代码行数:63,代码来源:as-task.ts



注:本文中的common/types.isCancelled函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript types.IStore类代码示例发布时间:2022-05-25
下一篇:
TypeScript TypedArrayUtils.fillFallback函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap