def pool.put

bend-kit-concurrency@0.2.0.0 · concurrency.bend:179

import bend-kit-concurrency@0.2.0.0/concurrency.bend as Concurrency
import Base

179# Queues each job with its own reply channel, and answers the replies in order.
180def pool.put(~A: Type, ~B: Type, xs: List<A>, +q: Chan(A & Chan(B))) -> IO(List<Chan(B)>):
181  match xs:
182    case Nil{}:
183      IO.pure(List<Chan(B)>, Nil{})
184    case x <> rest:
185      do IO<List<Chan(B)>>:
186        reply : Chan(B) <- Chan.new(B, 1)
187        +r : Chan(B) = reply
188        sent : Result<&1, &1, A & Chan(B), Unit> <- Chan.send(A & Chan(B), q, (x, r))
189        replies : List<Chan(B)> <- pool.put(~A, ~B, rest, q)
190        return r <> replies

Uses (11)

Used by (1)