@f/gen-to-promise

Convert generator to promise.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
@f/gen-to-promise
001.2.07 years ago7 years agoMinified + gzip package size for @f/gen-to-promise in KB

Readme

gen-to-promise
!Build statustravis-imagetravis-url !Git taggit-imagegit-url !NPM versionnpm-imagenpm-url !Code stylestandard-imagestandard-url
Convert generator to promise.

Installation

$ npm install @f/gen-to-promise

Usage

var genToPromise = require('@f/gen-to-promise')

genToPromise(function * () {
  var students = yield fetch('/students').then((res) => res.json())
  var studentIds = students.map((student) => student.id)
  var teachers = yield fetch('/teachers.of', {body: {students: studentIds}}).then((res) => res.json())
  return teachers
}).then(function (teachers) {
  // teachers of students
})

API

genToPromise(gen)

  • gen - generator

Returns: a promise with all the "yieldeds" in gen resolved

License

MIT