
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
promise-try
Advanced tools
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.
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)
FAQs
wraps a synchronously executing function and returns a promise
The npm package promise-try receives a total of 22 weekly downloads. As such, promise-try popularity was classified as not popular.
We found that promise-try demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.