Skip to content

Instantly share code, notes, and snippets.

@tom-huntington
Last active July 3, 2022 02:35
Show Gist options
  • Save tom-huntington/a1dbdaf35e4497b8a34c936001ad4e42 to your computer and use it in GitHub Desktop.
Save tom-huntington/a1dbdaf35e4497b8a34c936001ad4e42 to your computer and use it in GitHub Desktop.
How connect works for senders/receivers

Notes on Erik Nieblers talk https://www.youtube.com/watch?v=xiaqNvqRB2E code: https://godbolt.org/z/dnrabsbdq

auto thenSender = then(just(42), [](int i) { return i + 1; });
auto thenOeration = connect(thenSender, cout_receiver{});
start(thenOperation);

The call stack goes

  1. then_operation::start
  2. just_operation::start
  3. then_receiver::set_value
  4. cout_receiver::set_value

So the structures must be nested as follows

then_operation { just_operation { then_receiver { cout_receiver {} } }

To do this first we must nest the senders

then_sender { just_sender {} }

then connect propogates down these nested senders. The first call to connect (then_sender::connect) places it's receiver parameter (cout_receiver) into a receiver (then_receiver) corresponding to the sender (then_sender)

A = then_receiver { cout_receiver }

but also the recursive conncet calls build up

B = then_operation { just_operation {...} }

The last connect (just_sender::connect) then nests these two nested structures connect has built

A { B } = then_operation { just_operation { then_receiver { cout_receiver {} } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment