Macadamian Blog

Coterminous: Blurring Javascript Boundaries

Jake Tober

A lot of effort goes into creating the pipes and tubes that connect the internet, but those same pipes and tubes create limitations that affect our designs and implementations. Coterminous aims to reduce the impact of the mechanics of the web

Coterminous: Blurring Javascript Boundaries

co·ter·mi·nous
kōˈtərmənəs

adjective
having the same boundaries or extent in space, time, or meaning.

A lot of effort goes into creating the pipes and tubes that connect the internet, but those same pipes and tubes create limitations that affect our designs and implementations. Coterminous is a JavaScript RPC solution I created during one of my recent CreativiDays here at Macadamian. It aims to reduce the impact of the mechanics of the web by bringing our apps into seemingly direct contact with the services and resources they need. Coterminous allows JavaScript environments to pass Objects, Dates, RegExps, Functions, Promises, Subscriptions, and all the primitives back and forth as if they were running locally.

Unlike traditional RPC solutions which connect clients and servers over integrated transports, Coterminous fuses any two JavaScript contexts over flexible transports. Why limit usefulness to just a client and a server?  How about connecting two clients? or two servers? or allow a single client to expand past the limitations of the window and let users create multiple context specific tabs that meet their needs and their preferred layout.

How Does It Work?

Coterminous achieves fusion by transparently tracking and serializing function references, promises, subscriptions, Dates, RegExps, and all the basic types too.  It will even handle graphs with cycles without so much as a hiccup.  For most intents and purposes the two sides behave as if the other side were right there executing locally.  Technically speaking, you don’t even need to limit yourself to two contexts.  Once you’ve connected two contexts, you can keep connecting more and more, as many as you need.  Coterminous can fuse any number of contexts and they will all behave as if acting as one single context.

Under the hood, Coterminous requires one thing; a reliable transport mechanism.  You must provide and maintain the message passing channel, though you can use any technology you desire to do so.  You could use sockets, rest calls, ajax, message ports, local storage, flash APIs, you could even use a USB stick and pass messages back and forth by hand.  Coterminous then handles all the handshaking, serializing, deserializing, proxy creation and maintenance.  All of this done transparently behind the scenes so that you can focus more on the business logic of what you need to do, rather than spending time forcing things into tubes.

Want to take Coterminous for a spin? You can read more and try it out here.