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


TypeScript util.promisify函數代碼示例

本文整理匯總了TypeScript中util.promisify函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript promisify函數的具體用法?TypeScript promisify怎麽用?TypeScript promisify使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了promisify函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: promisify

		.then(_ => promisify(fs.readFile)(OUT_FILE))
開發者ID:calebsander,項目名稱:structure-bytes,代碼行數:1,代碼來源:type.ts

示例2: truncate

export function truncate(path: string, len: number): Promise<void> {
	return promisify(fs.truncate)(path, len);
}
開發者ID:PKRoma,項目名稱:vscode,代碼行數:3,代碼來源:pfs.ts

示例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;
開發者ID:TF2PickupNET,項目名稱:TF2Pickup,代碼行數:29,代碼來源:steam-community.ts

示例4: lstat

export function lstat(path: string): Promise<fs.Stats> {
	return promisify(fs.lstat)(path);
}
開發者ID:PKRoma,項目名稱:vscode,代碼行數:3,代碼來源:pfs.ts

示例5: unlink

export function unlink(path: string): Promise<void> {
	return promisify(fs.unlink)(path);
}
開發者ID:PKRoma,項目名稱:vscode,代碼行數:3,代碼來源:pfs.ts

示例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;
開發者ID:sindresorhus,項目名稱:pageres,代碼行數:31,代碼來源:index.ts

示例7: exists

export function exists(path: string): Promise<boolean> {
	return promisify(fs.exists)(path);
}
開發者ID:PKRoma,項目名稱:vscode,代碼行數:3,代碼來源:pfs.ts

示例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!');
開發者ID:jamg44,項目名稱:NodeTyped,代碼行數:30,代碼來源:loadMocks.ts

示例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,
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:31,代碼來源:generator.ts

示例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>;
/**
開發者ID:image-js,項目名稱:core,代碼行數:31,代碼來源:write.ts


注:本文中的util.promisify函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。