Socket
Socket
Sign inDemoInstall

promise-result

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    promise-result

Simple wrapper for promise results.


Version published
Weekly downloads
4
decreased by-20%
Maintainers
1
Install size
5.04 kB
Created
Weekly downloads
 

Readme

Source

promise-result

Simple wrapper for promise results with status.

Installation

npm install --save promise-result

Example

Basic usage:

import { PromiseResult, pending, createFulfilled, createRejected, isFulfilled, isPending, isRejected } from 'promise-result';


let state: PromiseResult<string> = pending;

const myPromise = fetch('https://example.org/')
  .then(() => {
      state = createFulfilled('Everything is OK!');
  })
  .catch((error) => {
      state = createRejected(error);
  });

function doSomethingWithState() {
    if (isFulfilled(state)) {
        // Show user the result...
        show(state.result);
    }

    if (isPending(state)) {
        // Show user a loading icon...
        show(loading);
    }

    if (isRejected(state)) {
        // Show error message to user...
        show(state.error.message);
    }
}

FAQs

Last updated on 04 Feb 2022

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