Class ReadScope

java.lang.Object
privbot.context.ReadScope

public final class ReadScope extends Object
Reuses detached observations within one synchronous decision, never across decisions or threads. Open the scope inside the client-thread callback, using ctx.read(...). Do not dispatch actions or wait for changes inside a scope: confirmation reads must start a fresh scope.
  • Method Details

    • scope

      public static <T> T scope(Supplier<T> work)
      Runs work with a fresh observation cache, cleared when it returns. Nested calls join the outer scope instead of opening a new one. Call it on the thread that reads (normally inside a client-thread callback); the cache is thread-local.
    • once

      public static <T> T once(Object key, Supplier<T> read)
      Returns the value cached under key in the current scope, reading it once on first use. Outside a scope it simply calls read. Use an owner-specific key; equal keys identify the same observation within this scope.