Zone-based Layer Activation

Context-specific Behavior Adaptations across
Logically-connected Asynchronous Operations

Context-oriented Programming (COP) directly addresses context variability by providing dedicated language concepts: layers, units of modularity, store context-dependent behavior. During runtime, layers can be applied dynamically depending on the current context of the program.

Various activation means for layers have been proposed. One of the most frequently used activation means is dynamic extent. Using dynamic extent developers may activate layers for the duration of a message send. Dynamic extent ensures to automatically deactivate the corresponding layers at the end of the message send.

The design of Context-oriented Programming in general and dynamic extent in particular assume a synchronous execution model. In recent years, however, asynchronous programming became popular, especially in context of UI programming and client-server communication. In an asynchronous programming model the execution of a method may be postponed and resume execution at some later point in time.

While asynchronous semantics seemingly avoid a "callback hell", these execution models break with the linear control flow assumed by most Context-oriented Programming implementations. While we define dynamic extent through lexical scoping, asynchronous execution is not bound by the linear fashion of executing nested functions. Instead, execution scopes may overlap and interleave in time. As a result, the safe semantics of the dynamic extent activation means cannot be guaranteed anymore: layers might be missing from the current layer composition in a postponed asynchronous task, or might leak to code not intended to run with a certain behavior adaptation. Neither of the aforementioned cases is desirable.

Zone-based Layer Activation (Paper to appear) is a variant of dynamic extent that applies a behavior adaptation not only for the duration of a message send but also for all asynchronous operations scheduled within the message send, transitively. As a consequence, Zone-based Layer Activation provides a sufficient integration of dynamic extent-style context specification with asynchronous execution models.

We provide the library area51 as an extension to ContextJS that supports Zone-based Layer Activation.

Example Application: Querying Latest GitHub Commits

This page exemplifies a usage scenario for Zone-based Layer Activation: the following program queries the latest commits of a user on GitHub and performs further queries to enhance the displayed repositories with the time and message of the respective latest commit.

1
2
3
4
5
6
7
async function displayRepos() {
  const repos = await GitHub.repos()
  for (let repo of repos) {
    const commits = await repo.commits()
    display(repo, commits[0])
  }
}

Using this base behavior, you can query any one's public GitHub repositories by filling in the respective username. As a behavior variation, the AuthLayer allows access to private repositories given a GitHub access token.

Please select a variant for code execution:

You token is only required when you want to access your private repositories.