Uneventful
    Preparing search index...
    • Experimental

      Define a shared, configurable unit of work that's run on-demand, at most once

      A Target is like a service(), in that it's defined once, started on demand, and can be reused across calls to newRoot().

      But instead of being synchronously built when called, targets are asynchronously started on use: either by calling them directly or calling any of their methods (other than .used()).

      Type Parameters

      • T = void

      Parameters

      • Optionalrecipe: EventuallyReturns<T>

        An optional ActivityFn that will be started in a task when the target is first used. Its eventual return value or thrown error will commit the target and be passed on to the target's observer(s).

        (Important: when the recipe returns or throws, its task will be ended! Any processes, effects, etc. that need to last beyond the target's completion should be done by having the recipe start service()s or other separate, non-child tasks.)

        A target's recipe can be overridden using the .start(), .complete() or .fail() methods, so long as the target hasn't been started yet. (Similar to the way services' implementations can be overridden via their .set() and .replace() methods, but with slightly different mechanics since targets are started asynchronously.)

        Note that if no recipe is given when the target is created, it must be explicitly started, completed or failed. Otherwise, its observers will wait forever, as the target will never be started or committed. (So most targets should have a recipe, unless you're using it as a semaphore or a coordination point between other targets.)

      Returns Target<T>