java.lang.Object
com.machinezoo.hookless.CurrentReactiveScope
@DraftDocs("reactive freezes link, reactive pins link, reactive computation link") public class CurrentReactiveScope extends Object
Convenience methods to access current
ReactiveScope. All calls are forwarded to ReactiveScope.current() if it is not null. If ReactiveScope.current() is null, methods of this class provide safe fallback behavior, which is usually functionally equivalent to creating temporary ReactiveScope.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidblock()Mark the current reactive computation as reactively blocking.static booleanblocked()Returnstrueif the current reactive computation is reactively blocking.static <T> TFreezes result of specified computation.static <T> TPins result of specified computation.
-
Constructor Details
-
CurrentReactiveScope
public CurrentReactiveScope()
-
-
Method Details
-
block
public static void block()Mark the current reactive computation as reactively blocking. If there's no current reactive computation (ReactiveScope.current()isnull), this method has no effect. -
blocked
public static boolean blocked()Returnstrueif the current reactive computation is reactively blocking. If there's no current reactive computation (ReactiveScope.current()isnull), this method returnsfalse.- Returns:
-
trueif the current reactive computation is reactively blocking,falseotherwise - See Also:
-
freeze
Freezes result of specified computation. On first call with givenkey, returns result of evaluating thesupplier. On subsequent calls within the same reactive computation, returns the same result without calling thesupplier. If there's no current reactive computation (ReactiveScope.current()isnull), this method evaluatessupplieranew on every call. Thesuppliershould be always the same for givenkey.- Type Parameters:
-
T- type of value returned by thesupplier - Parameters:
-
key- identifier for particular frozen value, which implementsObject.equals(Object)andObject.hashCode() -
supplier- value supplier to evaluate - Returns:
-
value computed by
supplieror previously frozen value - See Also:
-
pin
Pins result of specified computation. On first call with givenkey, returns result of evaluating thesupplier. On subsequent calls within the same sequence of blocking reactive computations (pin lifetime), returns the same result without calling thesupplier. If there's no current reactive computation (ReactiveScope.current()isnull), this method evaluatessupplieranew on every call. Thesuppliershould be always the same for givenkey.- Type Parameters:
-
T- type of value returned by thesupplier - Parameters:
-
key- identifier for particular pinned value, which implementsObject.equals(Object)andObject.hashCode() -
supplier- value supplier to evaluate - Returns:
-
value computed by
supplieror previously pinned value - See Also:
-