File: .lake/packages/lean4/src/lean/Init/Data/Channel.lean

full_name: IO.Channel.State
code: /--
Internal state of an `Channel`.

We maintain the invariant that at all times either `consumers` or `values` is empty.
-/
structure Channel.State (α : Type) where
  values : Std.Queue α := ∅
  consumers : Std.Queue (Promise (Option α)) := ∅
  closed := false
  deriving Inhabited
goal: Type

full_name: IO.Channel.State.consumers
code: /--
Internal state of an `Channel`.

We maintain the invariant that at all times either `consumers` or `values` is empty.
-/
structure Channel.State (α : Type) where
  values : Std.Queue α := ∅
  consumers : Std.Queue (Promise (Option α)) := ∅
  closed := false
  deriving Inhabited
goal: Std.Queue (IO.Promise (Option α))

full_name: IO.Channel.State.values
code: /--
Internal state of an `Channel`.

We maintain the invariant that at all times either `consumers` or `values` is empty.
-/
structure Channel.State (α : Type) where
  values : Std.Queue α := ∅
  consumers : Std.Queue (Promise (Option α)) := ∅
  closed := false
  deriving Inhabited
goal: Std.Queue α

full_name: IO.Channel.State.closed
code: /--
Internal state of an `Channel`.

We maintain the invariant that at all times either `consumers` or `values` is empty.
-/
structure Channel.State (α : Type) where
  values : Std.Queue α := ∅
  consumers : Std.Queue (Promise (Option α)) := ∅
  closed := false
  deriving Inhabited
goal: Bool

full_name: IO.Channel.instInhabitedState
code: /--
Internal state of an `Channel`.

We maintain the invariant that at all times either `consumers` or `values` is empty.
-/
structure Channel.State (α : Type) where
  values : Std.Queue α := ∅
  consumers : Std.Queue (Promise (Option α)) := ∅
  closed := false
  deriving Inhabited
goal: {a : Type} → Inhabited (IO.Channel.State a)

full_name: IO.Channel
code: /--
FIFO channel with unbounded buffer, where `recv?` returns a `Task`.

A channel can be closed.  Once it is closed, all `send`s are ignored, and
`recv?` returns `none` once the queue is empty.
-/
def Channel (α : Type) : Type 
goal: Type

full_name: IO.instNonemptyChannel
code: instance : Nonempty (Channel α) 
goal: Nonempty (IO.Channel α)

full_name: IO.Channel.new
code: /-- Creates a new `Channel`. -/
def Channel.new : BaseIO (Channel α) 
goal: BaseIO (IO.Channel α)

full_name: IO.Channel.send
code: /--
Sends a message on an `Channel`.

This function does not block.
-/
def Channel.send (ch : Channel α) (v : α) : BaseIO Unit 
goal: BaseIO Unit

full_name: IO.Channel.close
code: /--
Closes an `Channel`.
-/
def Channel.close (ch : Channel α) : BaseIO Unit 
goal: BaseIO Unit

full_name: IO.Channel.recv?
code: /--
Receives a message, without blocking.
The returned task waits for the message.
Every message is only received once.

Returns `none` if the channel is closed and the queue is empty.
-/
def Channel.recv? (ch : Channel α) : BaseIO (Task (Option α)) 
goal: BaseIO (Task (Option α))

full_name: IO.Channel.forAsync
code: /--
`ch.forAsync f` calls `f` for every messages received on `ch`.

Note that if this function is called twice, each `forAsync` only gets half the messages.
-/
partial def Channel.forAsync (f : α → BaseIO Unit) (ch : Channel α)
    (prio : Task.Priority := .default) : BaseIO (Task Unit) 
goal: BaseIO (Task Unit)

full_name: IO.Channel.recvAllCurrent
code: /--
Receives all currently queued messages from the channel.

Those messages are dequeued and will not be returned by `recv?`.
-/
def Channel.recvAllCurrent (ch : Channel α) : BaseIO (Array α) 
goal: BaseIO (Array α)

full_name: IO.Channel.Sync
code: /-- Type tag for synchronous (blocking) operations on a `Channel`. -/
def Channel.Sync 
goal: Type

full_name: IO.Channel.sync
code: /--
Accesses synchronous (blocking) version of channel operations.

For example, `ch.sync.recv?` blocks until the next message,
and `for msg in ch.sync do ...` iterates synchronously over the channel.
These functions should only be used in dedicated threads.
-/
def Channel.sync (ch : Channel α) : Channel.Sync α 
goal: IO.Channel.Sync α

full_name: IO.Channel.Sync.recv?
code: /--
Synchronously receives a message from the channel.

Every message is only received once.
Returns `none` if the channel is closed and the queue is empty.
-/
def Channel.Sync.recv? (ch : Channel.Sync α) : BaseIO (Option α) 
goal: BaseIO (Option α)

full_name: _private.«.lake».packages.lean4.src.lean.Init.Data.Channel.0.IO.Channel.Sync.forIn
code: private partial def Channel.Sync.forIn [Monad m] [MonadLiftT BaseIO m]
    (ch : Channel.Sync α) (f : α → β → m (ForInStep β)) : β → m β 
goal: β → m β

full_name: IO.instForInSyncOfMonadLiftTBaseIO
code: /-- `for msg in ch.sync do ...` receives all messages in the channel until it is closed. -/
instance [MonadLiftT BaseIO m] : ForIn m (Channel.Sync α) α 
goal: ForIn m (IO.Channel.Sync α) α