1.3.1 • Published 6 years ago

yieldpromise v1.3.1

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

yieldpromise

Yield promises in generator functions

Getting started

  npm i -s yieldpromise

Usage

const run = require("yieldpromise");
const fetch = require("node-fetch");

// Using as a standalone function
run(function* main() {
  const a = yield fetch("https://jsonplaceholder.typicode.com/posts/1");
  const b = yield a.json();
  console.log(b);
});

Since run injects resolve and reject as parameters to the child generator function, it can be used inside promise chain

Example
const run = require("yieldpromise");
const fetch = require("node-fetch");

run(function* main(resolve, reject) {
  const a = yield fetch("https://jsonplaceholder.typicode.com/posts/1");
  const b = yield a.json();
  resolve(b);
})
  .then(x => x.userId)
  .then(console.log);
OR
const run = require("yieldpromise");
const fetch = require("node-fetch");

fetch("https://jsonplaceholder.typicode.com/posts/1")
  .then(x =>
    run(function* main(resolve, reject) {
      const a = yield x.json();
      const b = a.userId;
      resolve(b);
    })
  )
  .then(console.log);
1.3.1

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.5

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago