https://github.com/caseywebb/potato-promise
:sweet_potato: ES6 Promises, but lazier.
https://github.com/caseywebb/potato-promise
lazy lazy-evaluation promise
Last synced: about 2 months 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 (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T04:01:50.000Z (about 2 years ago)
- Last Synced: 2024-10-18T07:12:29.383Z (7 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
[](https://www.npmjs.com/package/potato-promise)

[](https://travis-ci.org/caseyWebb/potato-promise)
[](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) => ...)
```