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);
@bfncs
Copy link

bfncs commented Sep 5, 2017

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.

@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