# Exercise: Channel Patterns
#
# Channels enable powerful concurrent patterns:
#
# Producer-Consumer:
#   - One strand produces values, sends them
#   - Another consumes values, receives them
#
# Pipeline:
#   - Chain of strands, each transforms and passes on
#
# Fan-out/Fan-in:
#   - One producer, multiple consumers
#   - Multiple producers, one consumer
#
# Your task: Create a simple producer that sends multiple values.
# When done, delete the marker line below.

# I AM NOT DONE

: produce-values ( Channel -- )
    # Send 1, 2, 3 then close (drop the Bool results from send)
    dup 1 swap chan.send drop
    dup 2 swap chan.send drop
    dup 3 swap chan.send drop
    chan.close
;

: sum-from-channel ( Channel -- Int )
    # Receive all values and sum them
    # Your code here - receive until channel is empty
    drop 0
;

: test-patterns ( -- )
    chan.make
    dup produce-values
    sum-from-channel
    # Do not edit below this line
    6 test.assert-eq   # 1 + 2 + 3 i.= 6
;
