当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Client.connect方法代码示例

本文整理汇总了TypeScript中butlerd.Client.connect方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Client.connect方法的具体用法?TypeScript Client.connect怎么用?TypeScript Client.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在butlerd.Client的用法示例。


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

示例1: refreshButlerd

async function refreshButlerd(store: IStore) {
  logger.info(`Refreshing butlerd! Spinning up new instance...`);
  let instance = await makeButlerInstance();
  instance.promise().catch(e => {
    console.error(`butlerd instance threw:`);
    console.error(e.stack);
    refreshButlerd(store).catch(() => {});
  });
  const endpoint = await instance.getEndpoint();

  logger.info(`Connecting client...`);
  const nextClient = new Client(endpoint);
  await nextClient.connect();

  if (masterClient) {
    // instances exit gracefully when all clients have closed
    logger.info(`Closing old master client...`);
    masterClient.close();
    masterClient = null;
  }
  masterClient = nextClient;
  logger.info(`Got new endpoint`);
  store.dispatch(actions.gotButlerdEndpoint({ endpoint }));
  initialButlerdResolve();
}
开发者ID:HorrerGames,项目名称:itch,代码行数:25,代码来源:setup.ts

示例2: async

 sanityCheck: async (versionPrefix: string) => {
   const instance = await makeButlerInstanceWithPrefix(versionPrefix);
   // we're awaiting it later, avoid 'unhandledRejection'
   instance.promise().catch(() => {});
   try {
     const client = new Client(await instance.getEndpoint());
     await client.connect();
     await client.call(messages.VersionGet, {});
     client.close();
   } finally {
     await instance.promise();
   }
 },
开发者ID:HorrerGames,项目名称:itch,代码行数:13,代码来源:formulas.ts

示例3: getRootState

export async function withButlerClient<T>(
  parentLogger: Logger,
  cb: WithCB<T>
): Promise<T> {
  const { endpoint } = getRootState().butlerd;
  if (!endpoint) {
    throw new Error(`no butlerd endpoint yet`);
  }
  const client = new Client(endpoint);
  await client.connect();
  setupLogging(client, parentLogger);

  let res: T;
  let err: Error;
  try {
    res = await cb(client);
  } catch (e) {
    if (getRootState().system.quitting) {
      // ignore butlerd error when quitting
    } else {
      console.error(`Caught butler error:`);
      if (isInternalError(e)) {
        const ed = getRpcErrorData(e);
        if (ed) {
          console.error(`butler version: ${ed.butlerVersion}`);
          console.error(`Golang stack:\n${ed.stack}`);
        }
        console.error(`JavaScript stack: ${e.stack}`);
      } else {
        console.error(`${e.message}`);
      }
      err = e;
    }
  } finally {
    client.close();
  }

  if (err) {
    throw err;
  }
  return res;
}
开发者ID:HorrerGames,项目名称:itch,代码行数:42,代码来源:utils.ts

示例4: async

    work: async () => {
      client = new Client(store.getState().butlerd.endpoint);
      await client.connect();
      try {
        setupClient(client, logger, ctx);

        client.on(messages.PickManifestAction, async ({ actions }) => {
          const index = await pickManifestAction(store, actions, game);
          return { index };
        });

        client.on(messages.HTMLLaunch, async params => {
          return await performHTMLLaunch({
            ctx,
            logger,
            game,
            params,
          });
        });

        client.on(messages.ShellLaunch, async ({ itemPath }) => {
          shell.openItem(itemPath);
          return {};
        });

        client.on(messages.URLLaunch, async ({ url }) => {
          store.dispatch(actions.navigate({ window: "root", url }));
          return {};
        });

        client.on(messages.PrereqsStarted, async ({ tasks }) => {
          prereqsStateParams = {
            gameTitle: game.title,
            tasks: {},
          };

          for (const name of Object.keys(tasks)) {
            const task = tasks[name];
            prereqsStateParams.tasks[name] = {
              fullName: task.fullName,
              order: task.order,
              status: PrereqStatus.Pending,
              progress: 0,
              eta: 0,
              bps: 0,
            };
          }

          prereqsModal = modalWidgets.prereqsState.make({
            window: "root",
            title: ["grid.item.installing"],
            message: "",
            widgetParams: prereqsStateParams,
            buttons: [
              {
                id: "modal-cancel",
                label: ["prompt.action.cancel"],
                action: actions.abortTask({ id: ctx.getTaskId() }),
                className: "secondary",
              },
            ],
            unclosable: true,
          });
          store.dispatch(actions.openModal(prereqsModal));
        });

        client.on(
          messages.PrereqsTaskState,
          async ({ name, status, progress, eta, bps }) => {
            if (!prereqsModal) {
              return;
            }

            let state = {
              ...prereqsStateParams.tasks[name],
              status,
              progress,
              eta,
              bps,
            };

            let tasks = {
              ...prereqsStateParams.tasks,
              [name]: state,
            };

            prereqsStateParams = { ...prereqsStateParams, tasks };

            store.dispatch(
              actions.updateModalWidgetParams(
                modalWidgets.prereqsState.update({
                  id: prereqsModal.id,
                  widgetParams: prereqsStateParams,
                })
              )
            );
          }
        );

        client.on(messages.PrereqsFailed, async ({ errorStack, error }) => {
//.........这里部分代码省略.........
开发者ID:HorrerGames,项目名称:itch,代码行数:101,代码来源:perform-launch.ts


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