Douglas Crockford

Blog

Books

Videos

2024 Appearances

JavaScript

Misty

JSLint

JSON

Github

Electric Communities

Mastodon/Layer8

Flickr Photo Album

ResearchGate

LinkedIn

Pronouns: pe/per

About

About The Parseq Demo

The Parseq Demo runs this Parseq program:

parseq.parallel(
    [
        widget("A"),
        parseq.race([
            widget("Race B0"),
            widget("Race B1"),
            widget("Race B2")
        ]),
        parseq.sequence([
            widget("Seq C0"),
            widget("Seq C1"),
            widget("Seq C2")
        ]),
        parseq.sequence([
            widget("Seq D0"),
            widget("Seq D1"),
            widget("Seq D2")
        ]),
        parseq.fallback([
            widget("Fall F0"),
            widget("Fall F1"),
            widget("Fall F2")
        ])
    ],
    [
        widget("Opt Q"),
        parseq.race([
            widget("Opt Race R0"),
            widget("Opt Race R1"),
            widget("Opt Race R2")
        ]),
        parseq.sequence([
            widget("Opt Seq S0"),
            widget("Opt Seq S1"),
            widget("Opt Seq S2")
        ]),
        parseq.sequence([
            widget("Opt Seq T0"),
            widget("Opt Seq T1"),
            widget("Opt Seq T2")
        ]),
        parseq.fallback([
            widget("Opt Fall V0"),
            widget("Opt Fall V1"),
            widget("Opt Fall V2")
        ])
    ]
)(show);

It executes two sets of requestors in parallel, and passes the result array to the show function which displays the result on the screen. The first array of requestors is required. All must be successful. The second array of requestors is optional. Some or all may fail, but the overall parallel operation may still succeed. Each widget represents a process that may be successful, in which case the result is the widget's name, or it may be unsuccessful, in which case the reason for failure will be the widget's name. Some of the widgets execute sequentially. Some execute as races or fallbacks.

You drive the demo by determining the success or failure of the widgets. If you decide a widget is successful, it turns green. If you decide a widget fails, it turns red. The success or failure of a widget may cause the starting of additional widgets.

Some situations can cause the cancellation of widgets whose work is no longer required, turning them gray. This happens to the stragglers in a race, or to the optional requestors when the required requestors complete.

In a real program, the widgets would be replaced with requestors that would send messages to other processes and handle the replies.