Skip to content

Instantly share code, notes, and snippets.

@namelos
Last active August 21, 2016 05:19
Show Gist options
  • Save namelos/e298e957844a9884f373525906bd8a3c to your computer and use it in GitHub Desktop.
Save namelos/e298e957844a9884f373525906bd8a3c to your computer and use it in GitHub Desktop.
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