p-try

WebJar for p-try

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

p-try
Last Version

Last Version

2.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

p-try
WebJar for p-try
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/sindresorhus/p-try

Download p-try

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/p-try/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>p-try</artifactId>
    <version>2.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/p-try/
implementation 'org.webjars.npm:p-try:2.2.0'
// https://jarcasting.com/artifacts/org.webjars.npm/p-try/
implementation ("org.webjars.npm:p-try:2.2.0")
'org.webjars.npm:p-try:jar:2.2.0'
<dependency org="org.webjars.npm" name="p-try" rev="2.2.0">
  <artifact name="p-try" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='p-try', version='2.2.0')
)
libraryDependencies += "org.webjars.npm" % "p-try" % "2.2.0"
[org.webjars.npm/p-try "2.2.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

p-try Build Status

Start a promise chain

How is it useful?

Install

$ npm install p-try

Usage

const pTry = require('p-try');

(async () => {
	try {
		const value = await pTry(() => {
			return synchronousFunctionThatMightThrow();
		});
		console.log(value);
	} catch (error) {
		console.error(error);
	}
})();

API

pTry(fn, ...arguments)

Returns a Promise resolved with the value of calling fn(...arguments). If the function throws an error, the returned Promise will be rejected with that error.

Support for passing arguments on to the fn is provided in order to be able to avoid creating unnecessary closures. You probably don't need this optimization unless you're pushing a lot of functions.

fn

The function to run to start the promise chain.

arguments

Arguments to pass to fn.

Related

  • p-finally - Promise#finally() ponyfill - Invoked when the promise is settled regardless of outcome
  • More…

Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

Versions

Version
2.2.0
2.1.0
2.0.0
1.0.0