ge">4 anos atrás l10n.php d01d7cf85d first commit 4 anos atrás link-template.php d01d7cf85d first commit 4 anos atrás load.php d01d7cf85d first commit 4 anos atrás locale.php d01d7cf85d first commit 4 anos atrás media-template.php d01d7cf85d first commit 4 anos atrás media.php d01d7cf85d first commit 4 anos atrás meta.php d01d7cf85d first commit 4 anos atrás ms-blogs.php d01d7cf85d first commit 4 anos atrás ms-default-constants.php d01d7cf85d first commit 4 anos atrás ms-default-filters.php d01d7cf85d first commit 4 anos atrás ms-deprecated.php d01d7cf85d first commit 4 anos atrás ms-files.php d01d7cf85d first commit 4 anos atrás ms-functions.php d01d7cf85d first commit 4 anos atrás ms-load.php d01d7cf85d first commit 4 anos atrás ms-network.php d01d7cf85d first commit 4 anos atrás ms-settings.php d01d7cf85d first commit 4 anos atrás ms-site.php d01d7cf85d first commit 4 anos atrás nav-menu-template.php d01d7cf85d first commit 4 anos atrás nav-menu.php d01d7cf85d first commit 4 anos atrás option.php d01d7cf85d first commit 4 anos atrás pluggable-deprecated.php d01d7cf85d first commit 4 anos atrás pluggable.php d01d7cf85d first commit 4 anos atrás plugin.php d01d7cf85d first commit 4 anos atrás post-formats.php d01d7cf85d first commit 4 anos atrás post-template.php d01d7cf85d first commit 4 anos atrás post-thumbnail-template.php d01d7cf85d first commit 4 anos atrás post.php d01d7cf85d first commit 4 anos atrás query.php d01d7cf85d first commit 4 anos atrás registration-functions.php d01d7cf85d first commit 4 anos atrás registration.php d01d7cf85d first commit 4 anos atrás rest-api.php d01d7cf85d first commit 4 anos atrás revision.php d01d7cf85d first commit 4 anos atrás rewrite.php d01d7cf85d first commit 4 anos atrás robots-template.php d01d7cf85d first commit 4 anos atrás rss-functions.php d01d7cf85d first commit 4 anos atrás rss.php d01d7cf85d first commit 4 anos atrás script-loader.php d01d7cf85d first commit 4 anos atrás session.php d01d7cf85d first commit 4 anos atrás shortcodes.php d01d7cf85d first commit 4 anos atrás sitemaps.php d01d7cf85d first commit 4 anos atrás spl-autoload-compat.php d01d7cf85d first commit 4 anos atrás taxonomy.php d01d7cf85d first commit 4 anos atrás template-canvas.php d01d7cf85d first commit 4 anos atrás template-loader.php d01d7cf85d first commit 4 anos atrás template.php d01d7cf85d first commit 4 anos atrás theme-i18n.json d01d7cf85d first commit 4 anos atrás theme-templates.php d01d7cf85d first commit 4 anos atrás theme.json d01d7cf85d first commit 4 anos atrás theme.php d01d7cf85d first commit 4 anos atrás update.php d01d7cf85d first commit 4 anos atrás user.php d01d7cf85d first commit 4 anos atrás vars.php d01d7cf85d first commit 4 anos atrás version.php d01d7cf85d first commit 4 anos atrás widgets.php d01d7cf85d first commit 4 anos atrás wlwmanifest.xml d01d7cf85d first commit 4 anos atrás wp-db.php d01d7cf85d first commit 4 anos atrás wp-diff.php d01d7cf85d first commit 4 anos atrás golf/tge - Gogs: Simplico Git Service

Nenhuma Descrição

golf d8e79ace03 index commit 3 anos atrás
..
History.md d8e79ace03 index commit 3 anos atrás
LICENSE d8e79ace03 index commit 3 anos atrás
README.md d8e79ace03 index commit 3 anos atrás
index.js d8e79ace03 index commit 3 anos atrás
package.json d8e79ace03 index commit 3 anos atrás

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
//   });
// });