Skip to content

Instantly share code, notes, and snippets.

@Avaq
Last active November 24, 2020 14:42
Show Gist options
  • Save Avaq/e7083ffc7972bb1d4c88239b51eb4a79 to your computer and use it in GitHub Desktop.
Save Avaq/e7083ffc7972bb1d4c88239b51eb4a79 to your computer and use it in GitHub Desktop.
Request adapted to work with Fluture
'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();
});
'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);
@Avaq
Copy link
Author

Avaq commented Nov 24, 2020

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