You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

promise-result

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-result

Simple wrapper for promise results.

1.1.2
latest
Source
npm
Version published
Weekly downloads
1
-75%
Maintainers
1
Weekly downloads
 
Created
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

Package last updated on 04 Feb 2022

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