1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 01:39:24 +02:00
Oinktube/node_modules/catering
2024-08-05 11:37:04 -03:00
..
index.d.ts Libs updates and new version with option to pin videos on channel 2024-08-05 11:37:04 -03:00
index.js Libs updates and new version with option to pin videos on channel 2024-08-05 11:37:04 -03:00
LICENSE Libs updates and new version with option to pin videos on channel 2024-08-05 11:37:04 -03:00
next-tick-browser.js Libs updates and new version with option to pin videos on channel 2024-08-05 11:37:04 -03:00
next-tick.js Libs updates and new version with option to pin videos on channel 2024-08-05 11:37:04 -03:00
package.json Libs updates and new version with option to pin videos on channel 2024-08-05 11:37:04 -03:00
readme.md Libs updates and new version with option to pin videos on channel 2024-08-05 11:37:04 -03:00

catering

Cater to callback and promise crowds.
Simple utility to allow your module to be consumed with a callback or promise. For Node.js and browsers.

npm status Node version Test Standard

Menu

If your module internally uses callbacks:

const { fromCallback } = require('catering')
const kPromise = Symbol('promise')

module.exports = function (callback) {
  callback = fromCallback(callback, kPromise)
  queueMicrotask(() => callback(null, 'example'))
  return callback[kPromise]
}

If your module internally uses promises:

const { fromPromise } = require('catering')

module.exports = function (callback) {
  return fromPromise(Promise.resolve('example'), callback)
}

Either way your module can now be consumed in two ways:

example((err, result) => {})
const result = await example()

When converting from a promise to a callback, fromPromise calls the callback in a next tick to escape the promise chain and not let it steal your beautiful errors.

Install

With npm do:

npm install catering

License

MIT © 2018-present Vincent Weevers. Originally extracted from levelup.