Last active
August 21, 2016 05:19
-
-
Save namelos/e298e957844a9884f373525906bd8a3c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const Subject = require('rxjs').Subject | |
const run = require('@cycle/rxjs-run').run | |
const http = require('http') | |
const makeServerDriver = port => { | |
const requests$ = new Subject() | |
http.createServer((req, res) => requests$.next({ req, res })) | |
.listen(port, _ => console.log(`listening on ${port}`)) | |
return sink$ => ( | |
sink$.zip(requests$, (sink, { req, res }) => ({ sink, res })) | |
.subscribe(({ sink, res }) => res.end(sink)), | |
requests$.map(({ req, res }) => req)) | |
} | |
const main = ({ server }) => ({ | |
server: server.map(req => `request for ${req.url}`) | |
}) | |
run(main, { server: makeServerDriver(3000) }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment