Home > CuteJS

CuteJS

CuteJS is a project mainly written in ..., it's free.

asynchronous algorithms simplified

CuteJS - asynchronous algorithms simplified

Copyright 2011, Daniel Kwiecinski Dual licensed under the MIT or GPL Version 2 licenses.

CuteJS is a set of utilities easing development of asynchronous activities in javascript. It contains agent implementation, mutual exclusion implementation and three behaviours: Serial, Tense and Lax.

Mutex - instance represents critical resource. It provides 'sync' method which wraps a function returning it thread-safe version.

Agent - this is analogy to clojure agents or erlang process. Namely, entity holding a state which can be mutated by asynchronous message passing.

Serial - a behaviour which allows to define dependency chain of asynchronous function calls. Results of asynchronous calls are provided as arguments to their callbacks, which in turn, pass the result to the next asynchronous call in chain.

Tense - a behaviour which allows to define concurrent asynchronous actions where the last scheduled action pre-empt waiting queue, so there is at most one action waiting for the resource and the most recent one cancels previous one. When the currently executing action finishes, the waiting starts immediately afterwards and new action can wait for its turn.

Eager - a behaviour which allows to define concurrent asynchronous actions whose results are collected and provided in single final callback. The asynchronous actions are executed in parallel and do not depend on each other. Eager is useful for example when we need to do single UI update which depends on several resources each accessed via separate ajax call.

Please check out the spec for working examples.

(to execute ajax spec, please run the server.sh script. It will start python static resource web-server. Point your browser to http://localhost:7778/spec/cute-spec-ajax.html)

Dependencies: CuteJS depends only on jQuery and it uses it only for ajax related functions. Shall you not need these please feel free not to include that dependency.