toShared

Wraps a Sender in a SharedSender. A SharedSender allows many receivers to connect to the same underlying Sender, forwarding the same termination call to each receiver. The underlying Sender is connected and started only once. It can be explicitely reset so that it connects and starts the underlying Sender the next time it started. Calling reset when the underlying Sender hasn't completed is a no-op. When the last receiver triggers its stoptoken while the underlying Sender is still running, the latter will be cancelled and one termination function of the former will be called after the latter is completed. (This is to ensure structured concurrency, otherwise tasks could be left running without anyone awaiting them). If an receiver is connected after the underlying Sender has already been completed, that receiver will have one of its termination functions called immediately. This operation is useful when you have multiple tasks that all depend on one shared task. It allows you to write the shared task as a regular Sender and simply apply a .toShared.

  1. auto toShared(Sender sender, Scheduler scheduler)
    toShared
    (
    Sender
    Scheduler
    )
    (
    Sender sender
    ,
    Scheduler scheduler
    )
  2. auto toShared(Sender sender)

Meta