# Exercise: Worker Pool
#
# Multiple workers processing from the same channel.
#
# Pattern:
#   - Create a work channel
#   - Spawn multiple workers, all reading from it
#   - Send work items
#   - Workers grab items as they're free
#
# This naturally load-balances work across workers.
#
# Your task: Spawn two workers that each process one item.
# When done, delete the marker line below.

# I AM NOT DONE

: test-worker-pool ( -- )
    chan.make   # work channel
    chan.make   # results channel
    # Stack: ( work results )

    # Spawn two workers that receive work, add 1, send to results
    2dup [ over chan.receive drop 1 i.+ swap chan.send drop drop ] strand.spawn drop
    drop drop   # clean up extra channels: ( work results )
    2dup [ over chan.receive drop 1 i.+ swap chan.send drop drop ] strand.spawn drop
    drop drop   # clean up: ( work results )

    # Send two work items
    over 10 swap chan.send drop
    over 20 swap chan.send drop

    # Receive two results and sum them
    # Your code here - receive both results, sum them, clean up channels
    drop drop 0
    # Do not edit below this line
    # Results are 11 and 21, sum is 32
    32 test.assert-eq
;
