run<T> method
Runs a function within this scope's context.
Parameters:
fn: Function to execute within the scope
Returns: The result of the function execution
Example:
final scope = EffectScope();
final result = scope.run(() {
final signal = Signal(42);
return signal.value;
});
Implementation
@override
T run<T>(T Function() fn) {
final prevSub = setActiveSub(this);
final prevScope = setActiveScope(this);
try {
final result = fn();
JoltDebug.effect(this);
return result;
} finally {
setActiveScope(prevScope);
setActiveSub(prevSub);
}
}