Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/caseywebb/potato-promise
:sweet_potato: ES6 Promises, but lazier.
https://github.com/caseywebb/potato-promise
lazy lazy-evaluation promise
Last synced: 9 days ago
JSON representation
:sweet_potato: ES6 Promises, but lazier.
- Host: GitHub
- URL: https://github.com/caseywebb/potato-promise
- Owner: caseyWebb
- Created: 2016-12-20T22:46:15.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T04:01:50.000Z (almost 2 years ago)
- Last Synced: 2024-10-18T07:12:29.383Z (2 months ago)
- Topics: lazy, lazy-evaluation, promise
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# potato-promise
[![NPM Version](https://img.shields.io/npm/v/potato-promise.svg)](https://www.npmjs.com/package/potato-promise)
![WTFPL](https://img.shields.io/npm/l/potato-promise.svg)
[![Travis](https://img.shields.io/travis/caseyWebb/potato-promise.svg)](https://travis-ci.org/caseyWebb/potato-promise)
[![NPM Downloads](https://img.shields.io/npm/dt/potato-promise.svg?maxAge=2592000)](http://npm-stat.com/charts.html?package=potato-promise&author=&from=&to=)Super [tiny](./index.js), dependency-free wrapper to make promises lazy, i.e. sit there like a potato until `.then()` is invoked.
Assumes native promises, or at least `Promise` on the global scope (`global` or `window`).
### Installation
```bash
$ npm i -S potato-promise
```### Usage
```javascript
const Potato = require('potato-promise')const p = new Potato((resolve) => {
console.log(3)
resolve()
})console.log(1)
setTimeout(() => {
console.log(2)
p.then(() => {}).catch(() => {})
}, 1000)// > 1
// ...after 1 second...
// > 2
// > 3
```__Note:__ I'm only using `new` here for familiar semantics; this is actually
a factory function. The following would also work...```javascript
Promise.lazy = require('potato-promise')const p = Promise.lazy((resolve) => ...)
```