Introducing Mahlee™

Created 7th January, 2007 11:09 (UTC), last edited 3rd November, 2007 10:31 (UTC)

Mahlee™ is a JavaScript host extension that makes it easy to write multi-threaded and distributed applications.

Mahlee™ works by subverting the normal JavaScript message delivery system to allow messages to be delivered between different threads, different processes or even different computers. It only needs to make a few changes to the normally hidden interstitial message passing and binding in JavaScript and the only difference in using Mahlee™ objects is a small change to the return type of a message invocation and a small change to the way that objects are created.

Creating an object
// Normal way of creating an object
object = new Foo( bar );

// Creating the object in another thread using Mahlee
object = Mahlee.create( Foo, bar );
Invoking a method
// Normal Invocation of a method on an object
result = bar );

// Synchronous invocation of a method using Mahlee
result = bar ).result();

// Asynchronous invocation of a method using Mahlee
future = bar );
  // Do more things
result = future.result();

Mahlee™ was originally conceived as an aid to explain and understand object oriented systems, especially the ideas behind message dispatchers and binding. This is because Mahlee™ doesn't use a shared memory multi-threading environment, rather it uses message passing¹ [1The message passing mechanism means that the processing model approaches that used by languages like Erlang called “communicating sequential processes” (CSP).].

Mahlee™ actually turns out to be a very practical and useful thing too.

A Mahlee™ program is simply a standard JavaScript script written to use some extra features of the host environment. As such Mahlee™ can be embedded into other systems (web browsers, desktop applications etc.) and can be supported on a wide variety of platforms.

The message protocols that Mahlee™ uses (based on JSON) can be written for other scripting languages or compiled languages and I hope they will. In fact the same message passing concepts are used in the C++ implementation of the current Mahlee™ host.

High level aims

There are a number of things that I want to ensure that Mahlee™ is always capable of because I think it will help to drive adoption and development of Mahlee™ in as many different application areas as possible.

Implementable in JavaScript

The alpha version of Mahlee™ comes in two implementations. The first is a JavaScript implementation that simulates the features of the multi-threaded host extension but works within a single threaded architecture. The second is a simple multi-threaded extension that does run objects in separate threads.

Preserving the ability to simulate Mahlee™ purely in JavaScript will help people to write and debug new implementations of Mahlee™ host extensions (as there will always be a second implementation to test against) and will help those who do not have access to a Mahlee™ host to write Mahlee™ scripts.

A single global

There are various reasons for choosing the Mahlee™ name, but one of them is that it currently returns zero hits on Google's code search² [2Actually not zero, but the only matches were for a host name in a configuration file.]. This is important because having a global name that is not already in use means that Mahlee™ can easily be added to scripts (this follows on from the previous point of course).

This will help scripts to degrade gracefully where Mahlee™ is not available.

Narrow API

In keeping with the basic philosophy of FOST.3™ the Mahlee™ implementation should internalise as much of the complexity of dealing with multiple threads and object communication as possible.

When there is a choice between making implementations harder to write and making writing Mahlee™ scripts harder the choice will always be to make the scripts easy to write.

This is not to say that any thing that a script writer may want to do will be allowed by Mahlee™.


No Mahlee™ script should be allowed to do anything that the person who runs the scripts doesn't expect.

We have started to work out a meta-communication and meta-object layer called Sua which will handle communication between objects running in different processes or hosts. At the moment there aren't any details to report.

Cooperation from the language runtime shouldn't be needed

This is true for the current Windows™ implementation and should be true of other implementations too. This will help to make Mahlee™ much easier to implement.

Use of the Mahlee™ name

I want to keep the Mahlee™ name used for host extensions that are fully compatible with the “official” implementation.

I would very much like to see other implementations (especially for other environments or for other languages), but would just ask that efforts are coordinated in order to make the ideas as universal as possible and that different Mahlee™ implementations for the same language are fully compatible.

Feel free to do something similar for your favourite language, but if it isn't 100% compatible with Mahlee™ then please just call it something else.

The Mahlee™ object model

Mahlee™ objects are simply JavaScript objects that run in a special context. This means that a Mahlee™ object can already do anything that a normal JavaScript object can do³ [3There are however certain types of constructor that are not supported by Mahlee™ at the moment. I don't expect this to be insurmountable though.]. The Mahlee™ host extension is able to co-ordinate between Mahlee™ objects running in different threads and in the future different Mahlee™ hosts, even those running on different machines.

Mahlee™ objects communicate asynchronously through sending each other messages. When a Mahlee™ object sends another object a message it immediately receives a future which can be used to retrieve the result (or an error) at a later time. When the result is needed the calling Mahlee™ object will automatically wait for it.

Because Mahlee™ objects will be able to communicate between servers it is also possible to write Mahlee™ objects in languages other than JavaScript so long as they handle the Mahlee™ message protocol correctly.

A simple Mahlee™ program

Here is a simple “Hello world” program that creates an object in another thread and then retrieves the words “Hello” and “World” from it.

function HelloWorld() {

HelloWorld.prototype.hello = function() {
	return "Hello";
} = function() {
	return "World!";

function main() {
	var helloworld = Mahlee.create( HelloWorld );
	var hello = helloworld.hello();
	var world =;

	FHost.echo( hello.result() + " " + world.result() );

A normal JavaScript object is created (HelloWorld) which is then instantiated through the Mahlee™ host extension into a second thread. Two messages are sent to the object and the results are then put together which the host then prints out.

Mahlee™ remoting

The current (alpha) implementation of Mahlee™ doesn't support connection to remote objects. This is a description of what I am working on.

Mahlee™ remoting will allow Mahlee™ objects to be created from remote definitions, to communicate between Mahlee™ hosts and even to access global Mahlee™ objects.

Security will be handled by an out-of-band (or meta-communications) layer called Sua. Sua will be responsible for establishing trust relationships and capability determination (meta-object communications).

With Mahlee™ remoting it will become much simpler to write a wide variety of distributed programs, for example many distributed map-reduce or grid computing algorithms. Sua will also be responsible for charging of rented computer resources.

Remote Mahlee™ object definitions

Mahlee™ objects will be creatable through remote definitions. Here is the same Hello world example using remoting:

function main() {
	var display = Mahlee.create( "" );
	var hello = display.hello();
	var world =;

	FHost.echo( hello.result() + " " + world.result() );

This time the object definition is fetched from the remote server and executed locally.

Accessing global objects

It will also be possible to bind to global objects running on remote servers.

function main() {
	var display = Mahlee.bind( "" );
	var hello = display.hello();
	var world =;

	FHost.echo( hello.result + " " + world.result );

Here a single, literally global, object exists. The Mahlee™ host binds to this object after which using it is identical in nature to a local object.

Getting Mahlee™

An alpha version is available for Windows™.


  1. 99 Bottles of Beer