本文整理汇总了TypeScript中util.promisify函数的典型用法代码示例。如果您正苦于以下问题:TypeScript promisify函数的具体用法?TypeScript promisify怎么用?TypeScript promisify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了promisify函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: promisify
.then(_ => promisify(fs.readFile)(OUT_FILE))
示例2: truncate
export function truncate(path: string, len: number): Promise<void> {
return promisify(fs.truncate)(path, len);
}
示例3: debug
import SteamCommunity from 'steamcommunity';
import { promisify } from 'util';
import debug from 'debug';
import config from 'config';
const log = debug('TF2Pickup:utils:steam-community');
const steamCommunity = new SteamCommunity();
const login = promisify(steamCommunity.login.bind(steamCommunity));
const username = config.get<string | null>('services.steam.username');
const password = config.get<string | null>('services.steam.password');
export async function setupSteam() {
if (password === null || username === null) {
return;
}
try {
await login({
accountName: username,
password,
});
log('Successfully logged into steam');
} catch (error) {
log('Error while logging into steam', { error });
}
}
export default steamCommunity;
示例4: lstat
export function lstat(path: string): Promise<fs.Stats> {
return promisify(fs.lstat)(path);
}
示例5: unlink
export function unlink(path: string): Promise<void> {
return promisify(fs.unlink)(path);
}
示例6: promisify
import getRes from 'get-res';
import logSymbols from 'log-symbols';
import mem from 'mem';
import makeDir from 'make-dir';
import captureWebsite from 'capture-website';
import viewportList from 'viewport-list';
import filenamify from 'filenamify';
import filenamifyUrl from 'filenamify-url';
import template from 'lodash.template';
import plur from 'plur';
import unusedFilename from 'unused-filename';
// TODO: Move this to `type-fest`
type Mutable<ObjectType> = {-readonly [KeyType in keyof ObjectType]: ObjectType[KeyType]};
const writeFile = promisify(fs.writeFile);
export interface Options {
readonly delay?: number;
readonly timeout?: number;
readonly crop?: boolean;
readonly css?: string;
readonly script?: string;
readonly cookies?: readonly (string | {[key: string]: string})[];
readonly filename?: string;
readonly incrementalName?: boolean;
readonly selector?: string;
readonly hide?: readonly string[];
readonly username?: string;
readonly password?: string;
readonly scale?: number;
示例7: exists
export function exists(path: string): Promise<boolean> {
return promisify(fs.exists)(path);
}
示例8: promisify
'use strict';
import { conn, Product, User } from '../models';
import { promisify } from 'util';
const readFile = promisify(require('fs').readFile);
conn.once('open', () => {
main().then(() => conn.close());
});
async function main() {
try {
let users = JSON.parse(await readFile('./initial_data/userMocks.json', 'utf8'));
console.log(`Read ${users.length} users.`);
for (let userData of users) {
const newUser = new User(userData);
let user = await newUser.save();
console.log(`Saved "${user.name}" (${user._id})`);
}
console.log('Users loaded!');
let products = JSON.parse(await readFile('./initial_data/productMocks.json', 'utf8'));
console.log(`Read ${products.length} products.`);
for (let productData of products) {
let newProduct = new Product(productData);
let product = await newProduct.save();
console.log(`Saved "${product.name}" (${product._id})`);
}
console.log('Products loaded!');
示例9: make_debugLog
// tslint:disable:no-console
import * as fs from "fs";
import * as path from "path";
import * as ts from "typescript";
import { promisify } from "util";
import { assert } from "node-opcua-assert";
import { checkDebugFlag, make_debugLog } from "node-opcua-debug";
import { ConstructorFunc } from "node-opcua-factory";
import { get_class_tscript_filename, produce_tscript_code } from "./factory_code_generator";
const debugLog = make_debugLog(__filename);
const doDebug = checkDebugFlag(__filename);
const fileExists = promisify(fs.exists);
const mkdir = promisify(fs.mkdir);
/**
* @module opcua.miscellaneous
* @class Factory
* @static
*/
function compileTscriptCode(typescriptFilename: string): string {
const content = fs.readFileSync(typescriptFilename, "ascii");
const compilerOptions = {
module: ts.ModuleKind.CommonJS,
target: ts.ScriptTarget.ES2016,
示例10: promisify
import { writeFile, writeFileSync } from 'fs';
import { extname } from 'path';
import { promisify } from 'util';
import { Image } from '../Image';
import {
encode,
ImageFormat,
IEncodeOptionsPng,
IEncodeOptionsJpeg
} from './encode';
const writeFilePromise = promisify(writeFile);
/**
* Write an image to the disk.
* The file format is determined automatically from the file's extension.
* If the extension is not supported, an error will be thrown.
*/
export async function write(path: string, image: Image): Promise<void>;
/**
* Write an image to the disk as PNG.
* When the `png` format is specified, the file's extension doesn't matter.
*/
export async function write(
path: string,
image: Image,
options: IEncodeOptionsPng
): Promise<void>;
/**