Skip to content
This repository was archived by the owner on Sep 10, 2022. It is now read-only.
This repository was archived by the owner on Sep 10, 2022. It is now read-only.

Clarify global (shared?) state #3

@jeffposnick

Description

@jeffposnick

I've found that wrapping your head around global state tends to be a problem for developers who are using service workers for the first time. (C.f. https://stackoverflow.com/questions/38835273/when-does-code-in-a-service-worker-outside-of-an-event-handler-run)

You cover this a little bit, with the idea of explaining the lifetime of a tasklet and also a hypothetical callback to save (and also load?) state, but I think it's worth getting in front of that as a potential source of confusion.

Here's a question that I have about the hypothetical behavior after reading the spec:

// tasklet.js
let count = 0;
export function increment() {
  return count++;
}
// app.js
const tasklet1 = await tasklet.addModule('tasklet.js');
const tasklet2 = await tasklet.addModule('tasklet.js');

 // This will log 0.
console.log(await tasklet1.increment());

 // This will.. also log 0? Or 1?
console.log(await tasklet2.increment());

// Will this always log 1 (or 2)? What if a lot of time has
// passed and tasklet1 was killed?
console.log(await tasklet1.increment());

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions