prescription-net

A net wrapper for Prescription the FRP library

npm install prescription-net
2 downloads in the last week
8 downloads in the last month

Prescription Net

This exposes the core node.js net module as a set of functions that return Prescription FRP Observables 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 subscribe() that one through and we subscribe to each of
// the sockets it's emit back to themselves (echo server)
server.listen(3000).connection.subscribe(function(observables) {
    observables.socket.subscribe(observables.socket);
});

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.map(function(data) {
    return data.toString();
}).subscribe(function(data) {
    console.log(data);
});
connect.subscribe(function() {
    socket.onNext("beep bop boop");
});
npm loves you