Narrating Prophetic Monks

    potato-promise

    1.0.0 • Public • Published

    potato-promise

    NPM Version WTFPL Travis NPM Downloads

    Super tiny, 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

    $ npm i -S potato-promise

    Usage

    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...

    Promise.lazy = require('potato-promise')
     
    const p = Promise.lazy((resolve) => ...)

    Keywords

    none

    Install

    npm i potato-promise

    DownloadsWeekly Downloads

    2

    Version

    1.0.0

    License

    WTFPL

    Last publish

    Collaborators

    • caseywebb