Context & concurrency

All together...


Don't be fooled by the smallness of the navigation. This chapter is one of the most subtile and powerful and deserve big attention. It talks about "concurrency programming" and is primordial to safe, modular and lightweight concurrency design.

For this, deepjs provides a single tool, called deep.context, that acts as a contextualised "global" namespace (it looks like an oxymore ;)).

The pattern was taken from Kris Zyp promise implementation. Thx to him...;)

This namespace is closely linked to promises, and could be seen as local promise's context.

The magic is that you always access this local context globally... From anywhere, just read deep.context (its an object) : it's your current local context.

By example, if 3 asyncrhoneous requests, made by 3 different users, arrive in almost the same time on a nodejs server, you could safely store the current request (or current jquery reference that you use to build html reponses, etc.) into this namespace.

deepjs take care of swapping deep.context(s) at each promise callback start. So, if you need the nodejs-request-object or the current jquery references : you only need to access this namespace . No more arguments cascade or tricky global management. You have it when you need it...

typical content

In this namespace, you could store any kind of objects or functions that you would access from anywhere in yours promises callbacks.

By example, OCM use it to store contextualised modes, some protocols could be stored there to be only accessible to certain users, etc.

Here is a list of common objects founded in this context :

  • Contextualised protocols
  • OCM modes
  • Current Http Request (server side)
  • Current Session (server side)
  • logger : to have contexualised logging mecanism
  • jQuery reference linked to current window
  • "global" dom nodes used in htmls
  • etc.