Inside-out promise; lets you call resolve and reject from outside the Promise constructor function.

Overview

@suchipi/defer

Inside-out promise; lets you call resolve and reject from outside the Promise constructor function.

Usage

{ const defer = new Defer (); if (Date.now() % 2 === 0) { defer.resolve("You did it!"); } else { defer.reject(new Error("Oh no!")); } return defer.promise; }">
import Defer from "@suchipi/defer";

function spinToWin(): Promise<string> {
  const defer = new Defer<string>();

  if (Date.now() % 2 === 0) {
    defer.resolve("You did it!");
  } else {
    defer.reject(new Error("Oh no!"));
  }

  return defer.promise;
}

License

MIT

You might also like...

CLI utility that parses argv, loads your specified file, and passes the parsed argv into your file's exported function. Supports ESM/TypeScript/etc out of the box.

cleffa CLI tool that: Parses argv into an object (of command-line flags) and an array of positional arguments Loads a function from the specified file

Mar 6, 2022

TS & JS Library for adaptive precision cursor for the web. Releases will come out soon! Meanwhile, check out the demo site:

Haha, cool cursor go brrrr... Table of Content What is this? Installation & Setup Installation Setup Usage Cursor controls Element settings Known issu

Nov 24, 2022

A VS Code extension to practice and improve your typing speed right inside your code editor. Practice with simple words or code snippets.

A VS Code extension to practice and improve your typing speed right inside your code editor. Practice with simple words or code snippets.

Warm Up 🔥 👨‍💻 A VS Code extension to practice and improve your typing speed right inside your code editor. Practice with simple words or code snipp

Dec 12, 2022

Nest multiple blocks inside lists of any kind of list (ordered, unordered, no marker, etc), or do away with list markers and use it like a repeater!

Nest multiple blocks inside lists of any kind of list (ordered, unordered, no marker, etc), or do away with list markers and use it like a repeater!

Nest multiple blocks inside lists of any kind of list (ordered, unordered, no marker, etc), or do away with list markers and use it like a repeater!

Dec 26, 2022

A plugin for Obsidian that can create input fields inside your notes and bind them to metadata fields.

Obsidian Meta Bind Plugin This plugin can create input fields inside your notes and bind them to metadata fields. New docs I am currently working on n

Jan 4, 2023

How often do you get asked about the gadgets or software that you use? If the answer is quite often, you should be trying show off out. Curate the list of gadgets and software and share it with your fans and followers.

How often do you get asked about the gadgets or software that you use? If the answer is quite often, you should be trying show off out. Curate the list of gadgets and software and share it with your fans and followers.

Show Off - Showcase your setup! How often do you get asked about the gadgets or software that you use? If the answer is quite often, you should be try

Nov 24, 2022

A small CLI utility to configure Japa inside an existing Node.js project

A small CLI utility to configure Japa inside an existing Node.js project

Mar 11, 2022

Clojure inside your Obsidian documents!

Clojure inside your Obsidian documents!

Obsidian Wielder Clojure inside your Obsidian documents! This Obsidian plugin allows you to use the full power of Clojure directly inside of your docu

Dec 18, 2022

A simple JavaScript library, to display a window inside of the browser

A simple JavaScript library, to display a window inside of the browser

WindowJS WindowJS is a simple JavaScript library, to display a functional window inside of the browser. Demo: prod.thalmann.it/windowjs/demo.html Navi

Dec 14, 2022
Owner
Lily Scott
Former Prettier Core Team member, Former Babel team member. Interested in JavaScript, Rust, Unity, VR, Dev Tooling, Dev Experience, React, and more.
Lily Scott
Multithread emulator. The wrun allows you to dynamically run a function inside a Web Worker on the client side, without the needing of a dedicated file

wrun This lib allows you to dynamically run a function inside a Web Worker on the client side, without the needing of a dedicated file. This means tha

Felippe Regazio 9 Nov 5, 2022
The node module that allows you to control your Ethereum revocation lists & resolve revocation keys.

Ethereum Revocation Registry Controller The controller module for interacting with EIP-5539-compatible Ethereum revocation lists. Motivation The EIP-5

spherity 4 Sep 27, 2022
Allows the public to easily report and track the geolocation of anyone or anything they spot outside, using a mobile app or web frontend.

LIVE DEMO: https://armytracker.com/ (tracking the invading Russian army in Ukraine) Attention: - If you'd like to help the project either as a program

Michal Certicky 9 Mar 27, 2022
100% type-safe query builder for node-postgres :: Generated types, call any function, tree-shakable, implicit type casts, and more

⚠️ This library is currently in alpha. Contributors wanted! tusken Postgres client from a galaxy far, far away. your database is the source-of-truth f

alloc 54 Dec 29, 2022
Interactive 3D plotting with a simple function call using Three.js

About Generate interactive 3d plots with a simple function call. Function returns a Three.js scene which can be customized as needed. Basic function c

Nathan Epstein 89 Oct 20, 2022
Resolve parallel promises in key-value pairs whilst maintaining type information

async-kv Resolves promises in key-value pairs maintaining type information. Prerequisites NodeJS 12 or later Installation npm i async-kv yarn add asyn

Tony Tamplin 4 Feb 17, 2022
Adds promise support (rejects(), doesNotReject()) to tape by decorating it using tape-promise.

Tape With Promises Adds promise support (rejects(), doesNotReject()) to tape by decorating it using tape-promise. Install npm install --save-dev @smal

Small Technology Foundation 3 Mar 21, 2022
Pack all your node_modules and other files you want inside your project to a zip file.

?? Node Modules Packer Use Cases | Usage | Examples | Headless | Benchmarks | Reference This is a library to package all your node_modules and other f

Vinicius Lourenço 14 Dec 1, 2022
A quickstart AWS Lambda function code generator. Downloads a template function code file, test harness file, sample SAM deffiniation and appropriate file structure.

Welcome to function-stencil ?? A quickstart AWS Lambda function code generator. Downloads a template function code file, test harness file, sample SAM

Ben Smith 21 Jun 20, 2022
Tries to execute sync/async function, returns a specified default value if the function throws

good-try Tries to execute sync/async function, returns a specified default value if the function throws. Why Why not nice-try with it's 70+ million do

Antonio Stoilkov 14 Dec 8, 2022