當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript async-utils.callback2函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。