_report_server/src/e3b5f9b81ef552c1fccf171a05fef32ab4714662/app/node_modules/sucrase">sucrase 30f7226d9a first commit 3 gadi atpakaļ supports-preserve-symlinks-flag 30f7226d9a first commit 3 gadi atpakaļ tailwind-color-palette 30f7226d9a first commit 3 gadi atpakaļ tailwindcss 30f7226d9a first commit 3 gadi atpakaļ thenify 30f7226d9a first commit 3 gadi atpakaļ thenify-all 30f7226d9a first commit 3 gadi atpakaļ to-regex-range 30f7226d9a first commit 3 gadi atpakaļ tr46 30f7226d9a first commit 3 gadi atpakaļ ts-interface-checker 30f7226d9a first commit 3 gadi atpakaļ uglify-js 30f7226d9a first commit 3 gadi atpakaļ underscore 30f7226d9a first commit 3 gadi atpakaļ upper-case 30f7226d9a first commit 3 gadi atpakaļ util-deprecate 30f7226d9a first commit 3 gadi atpakaļ valid-data-url 30f7226d9a first commit 3 gadi atpakaļ web-resource-inliner 30f7226d9a first commit 3 gadi atpakaļ webidl-conversions 30f7226d9a first commit 3 gadi atpakaļ whatwg-url 30f7226d9a first commit 3 gadi atpakaļ wrap-ansi 30f7226d9a first commit 3 gadi atpakaļ wrappy 30f7226d9a first commit 3 gadi atpakaļ y18n 30f7226d9a first commit 3 gadi atpakaļ yallist 30f7226d9a first commit 3 gadi atpakaļ yaml 30f7226d9a first commit 3 gadi atpakaļ yargs 30f7226d9a first commit 3 gadi atpakaļ yargs-parser 30f7226d9a first commit 3 gadi atpakaļ .yarn-integrity 30f7226d9a first commit 3 gadi atpakaļ tmt/tiger_frontend - Gogs: Simplico Git Service

No Description

golf 77628cf8bf first comm 3 years ago
..
History.md 77628cf8bf first comm 3 years ago
LICENSE 77628cf8bf first comm 3 years ago
README.md 77628cf8bf first comm 3 years ago
index.js 77628cf8bf first comm 3 years ago
package.json 77628cf8bf first comm 3 years ago

README.md

thenify

NPM version Build status Test coverage Dependency Status License Downloads

Promisify a callback-based function using any-promise.

  • Preserves function names
  • Uses a native promise implementation if available and tries to fall back to a promise implementation such as bluebird
  • Converts multiple arguments from the callback into an Array, also support change the behavior by options.multiArgs
  • Resulting function never deoptimizes
  • Supports both callback and promise style

An added benefit is that thrown errors in that async function will be caught by the promise!

API

fn = thenify(fn, options)

Promisifies a function.

Options

options are optional.

  • options.withCallback - support both callback and promise style, default to false.
  • options.multiArgs - change the behavior when callback have multiple arguments. default to true.

    • true - converts multiple arguments to an array
    • false- always use the first argument
    • Array - converts multiple arguments to an object with keys provided in options.multiArgs
  • Turn async functions into promises

var thenify = require('thenify');

var somethingAsync = thenify(function somethingAsync(a, b, c, callback) {
  callback(null, a, b, c);
});
  • Backward compatible with callback
var thenify = require('thenify');

var somethingAsync = thenify(function somethingAsync(a, b, c, callback) {
  callback(null, a, b, c);
}, { withCallback: true });

// somethingAsync(a, b, c).then(onFulfilled).catch(onRejected);
// somethingAsync(a, b, c, function () {});

or use thenify.withCallback()

var thenify = require('thenify').withCallback;

var somethingAsync = thenify(function somethingAsync(a, b, c, callback) {
  callback(null, a, b, c);
});

// somethingAsync(a, b, c).then(onFulfilled).catch(onRejected);
// somethingAsync(a, b, c, function () {});
  • Always return the first argument in callback
var thenify = require('thenify');

var promise = thenify(function (callback) {
  callback(null, 1, 2, 3);
}, { multiArgs: false });

// promise().then(function onFulfilled(value) {
//   assert.equal(value, 1);
// });
  • Converts callback arguments to an object
var thenify = require('thenify');

var promise = thenify(function (callback) {
  callback(null, 1, 2, 3);
}, { multiArgs: [ 'one', 'tow', 'three' ] });

// promise().then(function onFulfilled(value) {
//   assert.deepEqual(value, {
//     one: 1,
//     tow: 2,
//     three: 3
//   });
// });