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

TypeScript awaiting.callback函数代码示例

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

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



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

示例1: r_format

export async function r_format(
  input: string,
  _: ParserOptions,
  logger: any
): Promise<string> {
  // create input temp file
  const input_path: string = await callback(tmp.file);
  await callback(writeFile, input_path, input);

  // spawn the R formatter
  const r_formatter = formatR(input_path);

  // stdout/err capture
  let stdout: string = "";
  let stderr: string = "";
  // read data as it is produced.
  r_formatter.stdout.on("data", data => (stdout += data.toString()));
  r_formatter.stderr.on("data", data => (stderr += data.toString()));
  // wait for subprocess to close.
  let code = await callback(close, r_formatter);
  if (code) {
    const err_msg = `${stderr}`;
    logger.debug(`R_FORMAT ${err_msg}`);
    throw new Error(err_msg);
  }

  // all fine, we read from the temp file
  let output: Buffer = await callback(readFile, input_path);
  let s: string = output.toString("utf-8");

  return s;
}
开发者ID:DrXyzzy,项目名称:smc,代码行数:32,代码来源:r-format.ts


示例2: 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


示例3: get_listing_node10

export async function get_listing_node10(
  path: string,
  hidden: boolean = false
): Promise<ListingEntry[]> {
  const dir = HOME + "/" + path;
  const files: ListingEntry[] = [];
  let file: Dirent;
  for (file of await callback(readdir, { withFileTypes: true }, dir)) {
    if (!hidden && file.name[0] === ".") {
      continue;
    }
    let entry: ListingEntry;
    try {
      // I don't actually know if file.name can fail to be JSON-able with node.js -- is there
      // even a string in Node.js that cannot be dumped to JSON?  With python
      // this definitely was a problem, but I can't find the examples now.  Users
      // sometimes create "insane" file names via bugs in C programs...
      JSON.stringify(file.name);
      entry = { name: file.name };
    } catch (err) {
      entry = { name: "????", error: "Cannot display bad binary filename. " };
    }

    try {
      let stats: Stats;
      if (file.isSymbolicLink()) {
        entry.issymlink = true;
      }
      try {
        stats = await callback(stat, dir + "/" + entry.name);
      } catch (err) {
        // don't have access to target of link (or it is a broken link).
        stats = await callback(lstat, dir + "/" + entry.name);
      }
      entry.mtime = stats.mtime.valueOf() / 1000;
      if (file.isDirectory()) {
        entry.isdir = true;
        const v = await callback(readdir, dir + "/" + entry.name);
        if (hidden) {
          entry.size = v.length;
        } else {
          // only count non-hidden files
          entry.size = 0;
          for (let x of v) {
            if (x[0] != ".") {
              entry.size += 1;
            }
          }
        }
      } else {
        entry.size = stats.size;
      }
    } catch (err) {
      entry.error = `${entry.error ? entry.error : ""}${err}`;
    }
    files.push(entry);
  }
  return files;
}
开发者ID:DrXyzzy,项目名称:smc,代码行数:59,代码来源:directory-listing.ts


示例4: clang_format

export async function clang_format(
  input: string,
  options: ParserOptions,
  ext: string,
  logger: any
): Promise<string> {
  // create input temp file
  // we have to set the correct filename extension, because clang format uses it
  const input_path: string = await callback(tmp.file, { postfix: `.${ext}` });
  try {
    // logger.debug(`clang_format tmp file: ${input_path}`);
    await callback(writeFile, input_path, input);

    // spawn the html formatter
    let formatter;
    let indent = options.tabWidth || 2;

    switch (options.parser) {
      case "clang-format":
        formatter = run_clang_format(input_path, indent /*, logger*/);
        break;
      default:
        throw Error(
          `Unknown C/C++ code formatting utility '${options.parser}'`
        );
    }
    // stdout/err capture
    let stdout: string = "";
    let stderr: string = "";
    // read data as it is produced.
    formatter.stdout.on("data", data => (stdout += data.toString()));
    formatter.stderr.on("data", data => (stderr += data.toString()));
    // wait for subprocess to close.
    let code = await callback(close, formatter);
    if (code >= 1) {
      const err_msg = `C/C++ code formatting utility "${
        options.parser
      }" exited with code ${code}\nOutput:\n${stdout}\n${stderr}`;
      logger.debug(`clang-format error: ${err_msg}`);
      throw Error(err_msg);
    }

    // all fine, we read from the temp file
    let output: Buffer = await callback(readFile, input_path);
    let s: string = output.toString("utf-8");
    // logger.debug(`clang_format output s ${s}`);

    return s;
  } finally {
    unlink(input_path);
  }
}
开发者ID:DrXyzzy,项目名称:smc,代码行数:52,代码来源:clang-format.ts


示例5: html_format

export async function html_format(
  input: string,
  options: ParserOptions,
  logger: any
): Promise<string> {
  // create input temp file
  const input_path: string = await callback(tmp.file);
  try {
    await callback(writeFile, input_path, input);
    let html_formatter;

    try {
      // run the selected html formatter
      switch (options.parser) {
        case "html-tidy":
        case "tidy":
          html_formatter = await tidy(input_path);
          break;
        default:
          throw Error(`Unknown HTML formatter utility '${options.parser}'`);
      }
    } catch (e) {
      logger.debug(`Calling formatter raised ${e}`);
      throw new Error(
        `HTML formatter broken or not available. Is '${
          options.parser
        }' installed?`
      );
    }

    const { exit_code, stdout, stderr } = html_formatter;
    const code = exit_code;
    // logger.debug("html_format: code, stdout, stderr", code, stdout, stderr);
    // TODO exit code 1 is a "warning", which requires show-warnings yes
    const problem = options.parser === "html-tidy" ? code >= 2 : code >= 1;
    if (problem) {
      throw Error(
        `HTML formatter "${
          options.parser
        }" exited with code ${code}\nOutput:\n${[stdout, stderr].join("\n")}`
      );
    }

    // all fine, we read from the temp file
    let output: Buffer = await callback(readFile, input_path);
    let s: string = output.toString("utf-8");
    return s;
  } finally {
    // logger.debug(`html formatter done, unlinking ${input_path}`);
    unlink(input_path);
  }
}
开发者ID:DrXyzzy,项目名称:smc,代码行数:52,代码来源:html-format.ts


示例6: bib_format

export async function bib_format(
  input: string,
  options: ParserOptions,
  logger: any
): Promise<string> {
  // create input temp file
  const input_path: string = await callback(tmp.file);
  const output_path: string = await callback(tmp.file);
  try {
    await callback(writeFile, input_path, input);

    // spawn the bibtex formatter
    let bib_formatter;
    try {
      switch (options.parser) {
        case "bib-biber":
          bib_formatter = await biber(input_path, output_path);
          break;
        default:
          throw Error(`Unknown XML formatter utility '${options.parser}'`);
      }
    } catch (e) {
      logger.debug(`Calling Bibtex formatter raised ${e}`);
      throw new Error(
        `Bibtex formatter broken or not available. Is '${
          options.parser
        }' installed?`
      );
    }

    const { exit_code, stdout, stderr } = bib_formatter;
    const code = exit_code;

    const problem = code >= 1;
    if (problem) {
      const msg = `Bibtex formatter "${
        options.parser
      }" exited with code ${code}\nOutput:\n${stdout}\n${stderr}`;
      throw Error(msg);
    }

    // all fine, we read from the temp file
    let output: Buffer = await callback(readFile, output_path);
    let s: string = output.toString("utf-8");
    return s;
  } finally {
    // logger.debug(`bibtex formatter done, unlinking ${input_path}`);
    unlink(input_path);
    unlink(output_path);
  }
}
开发者ID:DrXyzzy,项目名称:smc,代码行数:51,代码来源:bib-format.ts


示例7: gofmt

export async function gofmt(
  input: string,
  options: ParserOptions,
  logger: any
): Promise<string> {
  // create input temp file
  const input_path: string = await callback(tmp.file);
  try {
    // logger.debug(`gofmt tmp file: ${input_path}`);
    await callback(writeFile, input_path, input);

    // spawn the html formatter
    let formatter;

    switch (options.parser) {
      case "gofmt":
        formatter = run_gofmt(input_path /*, logger*/);
        break;
      default:
        throw Error(`Unknown Go code formatting utility '${options.parser}'`);
    }
    // stdout/err capture
    let stdout: string = "";
    let stderr: string = "";
    // read data as it is produced.
    formatter.stdout.on("data", data => (stdout += data.toString()));
    formatter.stderr.on("data", data => (stderr += data.toString()));
    // wait for subprocess to close.
    let code = await callback(close, formatter);
    if (code >= 1) {
      stdout = cleanup_error(stdout, input_path);
      stderr = cleanup_error(stderr, input_path);
      const err_msg = `Gofmt code formatting utility "${
        options.parser
      }" exited with code ${code}\nOutput:\n${stdout}\n${stderr}`;
      logger.debug(`gofmt error: ${err_msg}`);
      throw Error(err_msg);
    }

    // all fine, we read from the temp file
    let output: Buffer = await callback(readFile, input_path);
    let s: string = output.toString("utf-8");
    // logger.debug(`gofmt_format output s ${s}`);

    return s;
  } finally {
    unlink(input_path); // don't wait and don't worry about any error.
  }
}
开发者ID:DrXyzzy,项目名称:smc,代码行数:49,代码来源:gofmt.ts


示例8: callback2

export async function callback2(f: Function, opts: any): Promise<any> {
  function g(cb): void {
    opts.cb = cb;
    f(opts);
  }
  return await awaiting.callback(g);
}
开发者ID:DrXyzzy,项目名称:smc,代码行数:7,代码来源:async-utils.ts


示例9: call

 async call(mesg: object, timeout_ms: number): Promise<any> {
   const resp = await callback(call, this.conn, mesg, timeout_ms);
   if (resp != null && resp.status === "error") {
     throw Error(resp.error);
   }
   return resp;
 }
开发者ID:DrXyzzy,项目名称:smc,代码行数:7,代码来源:api.ts


示例10: throttle

 const save_history_to_disk = throttle(async () => {
   try {
     await callback(writeFile, path, terminals[name].history);
   } catch (err) {
     console.log(`failed to save ${path} to disk`);
   }
 }, 15000);
开发者ID:DrXyzzy,项目名称:smc,代码行数:7,代码来源:server.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript awaiting.delay函数代码示例发布时间:2022-05-25
下一篇:
TypeScript await-timeout.set函数代码示例发布时间: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