IDEA: "Session" style API for a shared actor (like a Logger)

Issue #75 new
James Powell repo owner created an issue

Idea inspired by the Extensible Session Framework.

Named (or Singleton) actor resource where multiple callers Obtain session to common actor, with actor Launched on first Obtain, and automatically shut down if all Obtained addresses Released.

Use cases:

  • Logger
  • Shared Resource

Problems:

  • Who configures the shared resource (like specifying the Log file)?

Comments (3)

  1. Ross Smyth

    This sounds very similar to me to Rust’s LazyLock. Which configuration is done in development, then each thread can acquire the resource, and when acquired it checks if init or not. If it is then it is just acquired. If it is not, then it is init then acquired.

    There is also OnceLock which LazyLock uses internally. This one is similar, but the configuration is done at each point of resource acquisition (usually) with the get_or_init method. Whichever “wins” the race of configuration is the one that is configured, and all threads attempting the acquire/init the resource get the first one configured, even if their configuration is different.

  2. James Powell reporter

    Maybe I need an “Init” that configures but does not Launch the actor, then a “Get” that Launches/shutsdown the actor in a lazy fashion. I want to avoid any “race of configuration”.

  3. Ross Smyth

    Sure, but in my mind the point of singleton-like resource acquisitions like this is that it is transparent at the site of acquisition about when or if configuration has occurred. So if you still have to ensure a happens-before with a some sort of init/config step then I don’t see the need for having a special framework item for it. Making something in the same spirit as that on your own is easy enough.

  4. Log in to comment