Socket
Socket
Sign inDemoInstall

@coffeekraken/s-promise

Package Overview
Dependencies
630
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @coffeekraken/s-promise

As simple as a native Promise, this package extends it with events capabilities using the @coffeekraken/s-event-emitter one.


Version published
Weekly downloads
288
increased by18.52%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

@coffeekraken/s-promise

MIT 2.0.0-alpha.20 - Git repository

size downloads license discord

As simple as a native Promise, this package extends it with events capabilities using the @coffeekraken/s-event-emitter one.

Install

npm i @coffeekraken/s-promise

Promises with event capabilities

This SPromise class workds like a normal Promise but add the SEventEmitter capabilities like:

  • emit: emitting events
  • on: subscribe to events
  • pipe: pipe events to another SEventEmitter instance
  • And more...

Usage

Here's how to use our implementation:

import __SPromise from '@coffeekraken/s-promise';

function myInternalProcess() {
  return new __SPromise(({ resolve, reject, emit }) => {
    // emitting a log event
    emit('log', {
      value: 'Something cool',
    });
    resolve();
  });
}
function myStartingProcess() {
  return new __SPromise(async ({ resolve, reject, emit, pipe }) => {
    // start internal process AND pipe his events higher
    const promise = pipe(myInternalProcess());
    // listen for logs. Can be any event name you want as well...
    promise.on('log', (data, metas) => {
      // do something with the logs...
    });
    // resolving the promise with our internal process one
    resolve(promise);
  });
}

const promise = myStartingProcess();
promise.on('log', () => {});
// etc...

Settings

SPromiseSettingsInterface
treatCancelAs
resolve

Specify if a "cancel" event/call has to be treated like a "resolve", or like a "reject" a promise level

destroyTimeout
1

Specify after how many milliseconds the promise will be destroyed after a "finally" event

preventRejectOnThrow

Specify if you prefer your promise to be "resolved" when an underlying error is catched, or if is has to be rejected normally

emitLogErrorEventOnThrow
1

Specify if you want a "log" of type "error" to be emitted when an underlying error is catched

resolveAtResolveEvent

Specify if youw promise has to be resolved when catching a "resolve" event from deeper emitter

rejectAtRejectEvent

Specify if youw promise has to be rejected when catching a "reject" event from deeper emitter

resolveProxies

Specify some functions to be called just before resolving the promise. This function will take the current promise resolve value and must return the updated value

rejectProxies

Specify some functions to be called just before rejecting the promise. This function will take the current promise resolve value and must return the updated value

API

For more information about the API of this class, please check our API documentation

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Here's all the ways you can contact us listed:

discord email

FAQs

Last updated on 15 Sep 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc