Pull the value from a promise using pull-streams
$ npm install pull-promise
const toPull = require('pull-promise')
const pull = require('pull-stream')
const axios = require('axios')
pull(
toPull.source(axios.get('http://example.org/posts/1')),
pull.map((response) => response.body),
pull.log()
)
// -> "quia et suscipit\nsuscipit recusandae..."
Also available as
require('pull-promise/source')
Creates a source stream with the resolved promise value.
const toPull = require('pull-promise')
pull(
toPull.source(Promise.resolve(5)),
pull.log()
)
// -> 5
Also available as
require('pull-promise/through')
Creates a through stream with the resolved promise value as output. fn
is a function accepting the incoming value and returning a Promise
.
const toPull = require('pull-promise')
pull(
pull.values([2, 4, 8]),
toPull.through((v) => Promise.resolve(v * v)),
pull.log()
)
// -> 4, 16, 64
$ npm test