promise-try
wraps a synchronously executing function and returns a promise
Last updated 11 years ago by wbinnssmith .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install promise-try 
SYNC missed versions from official npm registry.

promise-try

Wraps a synchronously executing function and returns a promise that resolves to its return value and rejects its exceptions. API-compatible with Bluebird's Promise.try.

Accepts an alternate Promise implementation as input if the environment doesn't natively support them.

This module is meant to be a convenient standalone implementation of a Promise utility, but it doesn't provide an alternate Promise constructor and is less than 500 bytes minified and gzipped.

API

function promiseTry(fn, args, ctx, Promise)

fn - a synchronously executed function that may return or throw synchronously. This will be wrapped and returned as a promise.

args - arguments to applied to the passed function. If not an array, it will be passed as a single argument to the function. If an array, it will be spread across the function's parameters.

I personally don't like this API since one could never achieve passing the function a single argument that is an array, but this is here for compatibility with bluebird. Instead, one could just use something like .bind(null, [1, 2, 3]) when passing the function.

ctx - the context (this) to be used when the function is executed.

Again, one could just use .bind(ctx) on the original function

Promise an alternate Promise implementation to use (perhaps if a global one doesn't exist)

Current Tags

  • 1.0.1                                ...           latest (11 years ago)

1 Versions

  • 1.0.1                                ...           11 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (3)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |