A function, or class constructor producing a value that will be cached by a
service() accessor for the life of the root job. (Or until overridden via
a service accessor's set/unset methods.)
The function or constructor will be run in the then-current root job, and its
value cached. If the function is a native generator function, it is
automatically wrapped with fork(), so that its job will not end when
the generator ends, and the result can be waited on by multiple callers. (If
your factory is not a native generator function but still returns a
generator to produce an async result, you should wrap that generator with
fork before returning it.)
Note: if an original or replacement factory directly or indirectly requests
its own value (even via a service() accessor), an error is thrown to
prevent infinite recursion. An error is also thrown if a reactive value is
directly or indirectly accessed during the factory's execution, to prevent
your cached service from unintentionally retaining a stale value. (Rules
and fx() are unaffected, as they will update
their state as needed.)
A function, or class constructor producing a value that will be cached by a
service()accessor for the life of the root job. (Or until overridden via a service accessor's set/unset methods.)The function or constructor will be run in the then-current root job, and its value cached. If the function is a native generator function, it is automatically wrapped with fork(), so that its job will not end when the generator ends, and the result can be waited on by multiple callers. (If your factory is not a native generator function but still returns a generator to produce an async result, you should wrap that generator with fork before returning it.)
Note: if an original or replacement factory directly or indirectly requests its own value (even via a service() accessor), an error is thrown to prevent infinite recursion. An error is also thrown if a reactive value is directly or indirectly accessed during the factory's execution, to prevent your cached service from unintentionally retaining a stale value. (Rules and fx() are unaffected, as they will update their state as needed.)