prescription-net
v0.1.1
Published
A net wrapper for Prescription the FRP library
Downloads
3
Readme
Prescription Net
This exposes the core node.js net
module as a set of functions that
return Prescription FRP Observable
s instead of taking callbacks.
Example
Echo server:
var net = require("prescription-net");
// Create a server instance
var server = new net.Server();
// Make the server listen on port 3000, we're only interested in the connection
// Observable, so we flatMap() that one through and we subscribe to it's Socket
// transmissions and per Socket we forward the data back (echo server)
server.listen(3000).flatMap(function(observables) {
return observables.connection;
}).subscribe(
function(observables) {
observables.socket.subscribe(observables.socket);
},
function(error) {
console.log("Error: " + error);
}
);
TCP client:
var net = require("prescription-net");
var client = new net.Socket();
var observables = client.connect(3000);
var connect = observables.connect;
var socket = observables.socket;
socket.subscribe(
function(data) {
console.log(data.toString());
},
function(error) {
console.log("Error: " + error);
}
);
connect.subscribe(function() {
socket.onNext("beep bop boop");
});