I think the easiest way is using a Subject
to reemit events from express
.
var express = require('express');
var Rx = require('rxjs');
var app = express();
let subject = new Rx.Subject();
app.get('/', (req, res) => subject.next([req, res]));
subject
.do(a => console.log('123345'))
.subscribe(args => {
let [req, res] = args;
res.send('Hello World!');
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!')
});
The main difference is that you need to wrap [req, res]
as an array because you want to pass both to subject.next(...)
. This can be later unpacked with let [req, res] = args;
.
Unfortunately, you can't use Observable.bindCallback
because it takes just a single response from the wrapped function and then completes which is now what you want in this scenario.