# @steeringwaves/pinkypromise

> typescript promise library built with the real world in mind

Latest version **0.2.0** (published 2023-10-13) · ISC license · 0 weekly downloads

## Install

```sh
npm install @steeringwaves/pinkypromise
pnpm add @steeringwaves/pinkypromise
yarn add @steeringwaves/pinkypromise
bun add @steeringwaves/pinkypromise
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2023-10-13 |
| First published | 2022-09-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=12 |
| Dependencies | 2 |
| Unpacked size | 288.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | steeringwaves |
| Maintainers | maxattax, 1800alex |

## Links

- npm: https://www.npmjs.com/package/@steeringwaves/pinkypromise
- Repository: https://github.com/steeringwaves/pinkypromise
- Issues: https://github.com/steeringwaves/pinkypromise/issues
- npm.io page: https://npm.io/package/@steeringwaves/pinkypromise

## Dependencies (2)

- [bluebird](https://npm.io/package/bluebird.md) ^3.7.2
- [@steeringwaves/context](https://npm.io/package/@steeringwaves/context.md) ^0.0.6

## Recent versions

- 0.2.0 (latest) — 2023-10-13
- 0.1.1 — 2023-06-29
- 0.1.0 — 2023-04-12
- 0.0.4 — 2023-03-17
- 0.0.3 — 2022-10-07
- 0.0.2 — 2022-09-27
- 0.0.1 — 2022-09-27

## README

# @steeringwaves/pinkypromise

![workflow](https://github.com/github/docs/actions/workflows/test.yml/badge.svg)

A typescript promise library built for the real world.

## Installation

```sh
npm install @steeringwaves/context
npm install @steeringwaves/pinkypromise

# for typescript you also need typings for bluebird
npm install --save-dev @types/bluebird
```

## Example

### basic usage

```js
import Context from "@steeringwaves/context";
import PinkyPromise, { Cancelable } from "@steeringwaves/pinkypromise";

const fn = () =>
	new PinkyPromise(new Promise(resolve, reject) => {
		resolve();
	});

fn().then();
```

### retry conditions

```js
let count = 0;
const fn = () =>
	new PinkyPromise(
		new Promise(resolve, reject) => {
			count++;
			resolve();
		},
		{
			While: () => count < 10
		}
	);

fn()
	.then(() => {
		console.log(count); // 10
	})
	.catch((err) => {
		console.log(err);
	});
```

### retry conditions where condition is async

```js
let count = 0;
const fn = () =>
	new PinkyPromise(
		new Promise(resolve, reject) => {
			if (count < 10) {
				resolve();
			} else {
				reject();
			}
		},
		{
			While: () =>
				new Promise((resolve) => {
					count++;
					resolve();
				})
		}
	);

fn()
	.then(() => {
		console.log(count); // 10
	})
	.catch((err) => {
		console.log(err);
	});
```

### retry attempts

```js
let count = 0;
const fn = () =>
	new PinkyPromise(
		new Promise(resolve, reject) => {
			count++;
			if (count < 10) {
				reject();
			} else {
				resolve();
			}
		},
		{
			Interval: 100, // 100ms
			Retries: 10
		}
	);

// could also do fn().setInterval(100).setRetries(10)

fn()
	.then(() => {
		console.log(count); // 10
	})
	.catch((err) => {
		console.log(err);
	});
```

### using context

```js
const fn = () =>
	new PinkyPromise(
		new Promise(resolve, reject) => {
			callback();
			resolve();
		},
		{ Context: ctx }
	);

fn().then();

// or
const fn = () =>
	new PinkyPromise(new Promise(resolve, reject) => {
		callback();
		resolve();
	});

fn().setContext(ctx).then();
```

### typescript usage

```ts
import Context from "@steeringwaves/context";
import PinkyPromise, { Cancelable } from "@steeringwaves/pinkypromise";

const ctx = new Context();

const fn: Cancelable<void> = () =>
	new PinkyPromise(
		new Promise(resolve: any, reject: any) => {
			callback();
			resolve();
		},
		{ Context: ctx }
	);

fn().then();
```

---
_Source: https://npm.io/package/@steeringwaves/pinkypromise · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
