本文整理汇总了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;未经允许,请勿转载。 |
请发表评论