30 November 2007

Managed Asynchronous Execution Threads

Lately I've been working on a model to describe execution flows in Bindows markup. The simple idea was to remove the need for using JavaScript when defining application logic.

One of the first problems I faced was the dual nature of executions depending on whether they are synchronous or not.

Consider the following: A.value = B.value = C.value

In a synchronous thread, A gets the value of B that gets the value of C.
The requirement here is that A knows about B that knows about C.

In an asynchronous thread, C sets its value on B that sets its value on A.
The requirement here is that C knows about B that knows about A.

In both cases the expression is interpreted first from left to right (parsing), then right to left (execution). For asynchronous threads to work, each instance needs to maintain information about what preceded it in the parsing since asynchronous means that the thread breaks after the parsing.

Looking closer at this, I realized that always satisfying the above described dependencies could give a straightforward, flow based way of describing an action sequence in XML, regardless of asynchronous dependencies. This is when things really started getting interesting…



A.value = B.value = C.value could be described as:

<A>
<value>
<B>
<value>
<C>
<value>
.. my value ..
</value>
</C>
</value>
</B>
</value>
</A>







When the above is deserialized, the parent/child relation is the same as the left/right relation earlier described. Applying a parent property to each instance gives enough for successfully being able to traverse the dependencies in either direction.

Here is a small test where toString represent the normal case and returnValue represent the callback of an asynchronous dependency:



Object.prototype.toString = function (){
return this._value.toString();
}

Object.prototype.returnValue = function () {
if ( this.to_the_right_of )
this.to_the_right_of.returnValue()
else
alert( this._value )
}

A = {}
A.to_the_right_of = null // parent relation

A._value =
B = {}
B.to_the_right_of = A // parent relation

B._value =
C = {}
C.to_the_right_of = B // parent relation

C._value = ".. my value .."

// left to right (sync)
alert( A )

// right to left (async)
C.returnValue()






I'll elaborate more on this later, but today we release the Bindows implementation. Check it out in the Bindows™ 4.0 (beta) or in the Bindows™ blog (http://blog.bindows.net/?p=65)

3 comments:

Anonymous said...

There's a very nice short review in InfoWorld by Martin Heller. check it out at: http://weblog.infoworld.com/stratdev/archives/2007/11/three_new_produ.html

Niclas Norgren said...

The Bindows 4.0 beta 0712 is out :). Or rather, available to the selected ... (people that joined the beta program).
It contains some rewrite of the inner works and adds quite a lot to the exposed API.

Niclas Norgren said...

And now 4.0 final is out :o)