# Exercise: Two-Way Communication
#
# Strands can both send and receive through channels.
#
# Pattern: Request-Response
#   1. Main sends request
#   2. Worker receives, processes, sends response
#   3. Main receives response
#
# Your task: Spawn a worker that doubles numbers.
# When done, delete the marker line below.

# I AM NOT DONE

: spawn-doubler ( -- Channel Channel )
    # Create two channels: request and response
    chan.make   # request channel
    chan.make   # response channel
    # Spawn worker that reads from request, doubles, sends to response
    # Return both channels for main to use
    # Your code here
;

: test-communication ( -- )
    # This test is simplified - just verify you understand the pattern
    chan.make
    dup [
        dup chan.receive drop   # receive 21
        2 i.*                   # double it
        swap chan.send drop     # send 42
    ] strand.spawn drop
    drop    # clean up extra channel
    dup 21 swap chan.send drop
    # Your code: receive from channel, then clean up channel
    drop 0
    # Do not edit below this line
    42 test.assert-eq
;
