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

TypeScript async-utils.callback2函数代码示例

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

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



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

示例1: send_email_notification

async function send_email_notification(
  db: Database,
  key: Key,
  source: string
): Promise<void> {
  // Gather relevant information to use to construct notification.
  const user_names = await callback2(db.account_ids_to_usernames, {
    account_ids: [source]
  });
  const source_name = `${user_names[source].first_name} ${
    user_names[source].last_name
  }`;
  const project_title = await callback(
    db._get_project_column,
    "title",
    key.project_id
  );
  const subject = `[${trunc(project_title, 40)}] ${key.path}`;
  const url = `https://cocalc.com/projects/${key.project_id}/files/${key.path}`;
  const body = `${source_name} mentioned you in <a href="${url}">a chat at ${
    key.path
  } in ${project_title}</a>.`;
  let from: string;
  from = `${source_name} <${NOTIFICATIONS_EMAIL}>`;
  const to = await callback(db.get_user_column, "email_address", key.target);
  if (!to) {
    throw Error("no implemented way to notify target (no known email address)");
  }

  const category = "notification";

  // Send email notification.
  await callback2(send_email, { subject, body, from, to, category });
}
开发者ID:DrXyzzy,项目名称:smc,代码行数:34,代码来源:handle.ts


示例2: exec

export async function exec(opts: ExecOpts): Promise<ExecOutput> {
  let msg = await callback2(webapp_client.exec, opts);
  if (msg.status && msg.status == "error") {
    throw new Error(msg.error);
  }
  return msg;
}
开发者ID:DrXyzzy,项目名称:smc,代码行数:7,代码来源:client.ts


示例3: prettier

export async function prettier(
  project_id: string,
  path: string,
  options: ParserOptions
): Promise<void> {
  let resp = await callback2(webapp_client.prettier, {
    project_id,
    path,
    options
  });
  if (resp.status === "error") {
    let loc = resp.error.loc;
    if (loc && loc.start) {
      throw Error(
        `Syntax error prevented formatting code (possibly on line ${
          loc.start.line
        } column ${loc.start.column}) -- fix and run again.`
      );
    } else if (resp.error) {
      throw Error(resp.error);
    } else {
      throw Error("Syntax error prevented formatting code.");
    }
  }
}
开发者ID:DrXyzzy,项目名称:smc,代码行数:25,代码来源:client.ts


示例4: user_search

export async function user_search(opts: {
  query: string;
  query_id?: number;
  limit?: number;
  timeout?: number;
  admin?: boolean;
  active?: string;
}): Promise<User[]> {
  return callback2(webapp_client.user_search, opts);
}
开发者ID:DrXyzzy,项目名称:smc,代码行数:10,代码来源:client.ts


示例5: set_action

async function set_action(
  db: Database,
  key: Key,
  action: string
): Promise<void> {
  await callback2(db._query, {
    query: "UPDATE mentions SET action=$1",
    params: [action],
    where: key
  });
}
开发者ID:DrXyzzy,项目名称:smc,代码行数:11,代码来源:handle.ts


示例6: start_project

async function start_project(project_id: string) {
  // also check if the project is supposedly running and if
  // not wait for it to be.
  const projects = redux.getStore("projects");
  if (projects == null) {
    throw Error("projects store must exist");
  }

  if (projects.get_state(project_id) != "running") {
    // Encourage project to start running, if it isn't already...
    await callback2(webapp_client.touch_project, { project_id });
    if (projects.get_my_group(project_id) == "admin") {
      // must be viewing as admin, so can't start as below.  Just touch and be done.
      return;
    }
    await callback2(projects.wait, {
      until: () => projects.get_state(project_id) == "running"
    });
  }
}
开发者ID:DrXyzzy,项目名称:smc,代码行数:20,代码来源:connect.ts


示例7: determine_action

async function determine_action(db: Database, key: Key): Promise<Action> {
  const { project_id, path, target } = key;
  const result = await callback2(db._query, {
    query: `SELECT COUNT(*) FROM mentions WHERE project_id=$1 AND path=$2 AND target=$3 AND action = 'email' AND time >= NOW() - INTERVAL '${MIN_EMAIL_INTERVAL}'`,
    params: [project_id, path, target]
  });
  const count: number = parseInt(result.rows[0].count);
  if (count > 0) {
    return "ignore";
  }
  return "email";
}
开发者ID:DrXyzzy,项目名称:smc,代码行数:12,代码来源:handle.ts


示例8: record_error

export async function record_error(
  db,
  key: Key,
  action: string,
  error: string
): Promise<void> {
  await callback2(db._query, {
    query: "UPDATE mentions SET action=$1,error=$2",
    where: key,
    params: [action, error]
  });
}
开发者ID:DrXyzzy,项目名称:smc,代码行数:12,代码来源:handle.ts


示例9: start_project

export async function start_project(
  project_id: string,
  timeout: number = 60
): Promise<void> {
  const store = redux.getStore("projects");
  function is_running() {
    return store.get_state(project_id) === "running";
  }
  if (is_running()) {
    // already running, so done.
    return;
  }
  // Start project running.
  redux.getActions("projects").start_project(project_id);
  // Wait until running (or fails without timeout).
  await callback2(store.wait, { until: is_running, timeout });
}
开发者ID:DrXyzzy,项目名称:smc,代码行数:17,代码来源:client.ts


示例10: handle_all_mentions

export async function handle_all_mentions(db: any): Promise<void> {
  const result = await callback2(db._query, {
    select: ["time", "project_id", "path", "source", "target", "priority"],
    table: "mentions",
    where: "action is null" // no action taken yet.
  });
  if (result == null || result.rows == null) {
    throw Error("invalid result"); // can't happen
  }
  for (let row of result.rows) {
    const project_id: string = row.project_id;
    const path: string = row.path;
    const time: Date = row.time;
    const source: string = row.source;
    const target: string = row.target;
    const priority: number = row.priority;
    await handle_mention(
      db,
      { project_id, path, time, target },
      source,
      priority
    );
  }
}
开发者ID:DrXyzzy,项目名称:smc,代码行数:24,代码来源:handle.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript async-utils.callback_opts函数代码示例发布时间:2022-05-25
下一篇:
TypeScript smartq.defer函数代码示例发布时间: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