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
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
block()
Mark the current reactive computation as reactively blocking.static boolean
blocked()
Returnstrue
if the current reactive computation is reactively blocking.static <T> T
Freezes result of specified computation.static <T> T
Pins 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()Returnstrue
if the current reactive computation is reactively blocking. If there's no current reactive computation (ReactiveScope.current()
isnull
), this method returnsfalse
.- Returns:
-
true
if the current reactive computation is reactively blocking,false
otherwise - 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 evaluatessupplier
anew on every call. Thesupplier
should 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
supplier
or 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 evaluatessupplier
anew on every call. Thesupplier
should 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
supplier
or previously pinned value - See Also:
-