Last active
November 24, 2020 14:42
-
-
Save Avaq/e7083ffc7972bb1d4c88239b51eb4a79 to your computer and use it in GitHub Desktop.
Request adapted to work with Fluture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const request = require('request'); | |
const Future = require('fluture'); | |
module.exports = o => Future((l, r) => { | |
const socket = request(o, (err, res) => err ? l(err) : r(res)); | |
return () => socket.abort(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const request = require('./request'); | |
const {encase} = require('fluture'); | |
const eventualName = ( | |
request({url: 'https://api.github.com/users/avaq', headers: {'User-Agent': 'Avaq'}}) | |
.map(res => res.body) | |
.chain(encase(JSON.parse)) | |
.map(user => user.name) | |
); | |
const cancel = eventualName.fork(console.error, console.log); | |
process.on('SIGINT', cancel); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The approach described in this gist has been superseded by https://github.com/fluture-js/fluture-node/#http