Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

p-tap

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

p-tap

Tap into a promise chain without affecting its value or state

  • 3.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
20K
increased by44.66%
Maintainers
1
Weekly downloads
 
Created
Source

p-tap Build Status

Tap into a promise chain without affecting its value or state

Install

$ npm install p-tap

Usage

const pTap = require('p-tap');

Promise.resolve('unicorn')
	.then(pTap(console.log)) // Logs `unicorn`
	.then(value => {
		// `value` is still `unicorn`
	});
const pTap = require('p-tap');

getUser()
	.then(pTap(user => recordStatsAsync(user))) // Stats are saved about `user` async before the chain continues
	.then(user => {
		// `user` is the user from getUser(), not recordStatsAsync()
	});
const pTap = require('p-tap');

Promise.resolve(() => doSomething())
	.catch(pTap.catch(console.error)) // prints any errors
	.then(handleSuccess)
	.catch(handleError);

API

pTap(tapHandler)

Use this in a .then() method.

Returns a thunk that returns a Promise.

pTap.catch(tapHandler)

Use this in a .catch() method.

Returns a thunk that returns a Promise.

tapHandler

Type: Function

Any return value is ignored. Exceptions thrown in tapHandler are relayed back to the original promise chain.

If tapHandler returns a Promise, it will be awaited before passing through the original value.

  • p-log - Log the value/error of a promise
  • p-if - Conditional promise chains
  • p-catch-if - Conditional promise catch handler
  • More…

License

MIT © Sindre Sorhus

Keywords

FAQs

Package last updated on 12 Mar 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc