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); |
The approach described in this gist has been superseded by https://github.com/fluture-js/fluture-node/#http
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hiya, thanks for the great work on fluture!
I want to be able to just include a fluture-based request everywhere, so I made one from your example: https://github.com/bfncs/request-fluture
If you want to maintain something like this yourself, just let me know so we can exchange ownership or work out something else.