Skip to content

Conversation

@algebraic-dev
Copy link
Member

This PR refactors the Async module to use the Async type in all of the Async files.

@algebraic-dev algebraic-dev self-assigned this Sep 12, 2025
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Sep 12, 2025
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Sep 12, 2025

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 4b6eab762fa3c157b5454a7d804e56923655e88a --onto b64111d5a837bb5273978cf9945bb137a31777b7. You can force Mathlib CI using the force-mathlib-ci label. (2025-09-12 19:12:22)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 4b6eab762fa3c157b5454a7d804e56923655e88a --onto d869c38e7bee7d484040b758837be76f55db9498. You can force Mathlib CI using the force-mathlib-ci label. (2025-09-16 03:10:03)

@leanprover-bot
Copy link
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 4b6eab762fa3c157b5454a7d804e56923655e88a --onto d3dda9f6d4428a906c096067ecb75e432afc4615. You can force reference manual CI using the force-manual-ci label. (2025-09-12 19:12:23)

@algebraic-dev algebraic-dev changed the title refactor: replace Task with Async and minor changes to some basic Async functions feat: replace Task with Async and minor changes to some basic Async functions Sep 15, 2025
@algebraic-dev algebraic-dev changed the title feat: replace Task with Async and minor changes to some basic Async functions refactor: replace Task with Async and minor changes to some basic Async functions Sep 15, 2025
Copy link
Member

@TwoFX TwoFX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good modulo two comments.

@algebraic-dev algebraic-dev added this pull request to the merge queue Sep 20, 2025
Merged via the queue into master with commit 4881c30 Sep 20, 2025
14 checks passed
github-merge-queue bot pushed a commit that referenced this pull request Sep 24, 2025
This PR adds `Notify` that is a structure that is similar to `CondVar`
but it's used for concurrency. The main difference between
`Std.Sync.Notify` and `Std.Condvar` is that depends on a `Std.Mutex` and
blocks the entire thread that the `Task` is using while waiting. If I
try to use it with async and a lot of `Task`s like this:

```lean
def condvar : Async Unit := do
  let condvar ← Std.Condvar.new
  let mutex ← Std.Mutex.new false

  for i in [0:threads] do
    background do
      IO.println s!"start {i + 1}"
      await =<< (show IO (ETask _ _) from IO.asTask (mutex.atomically (condvar.wait mutex)))
      IO.println s!"end {i + 1}"

  IO.sleep 2000
  condvar.notifyAll
```

It causes some weird behavior because some tasks start running and get
notified, while others don’t, because `condvar.wait` blocks the `Task`
entire task and right now afaik it blocks an entire thread and cannot be
paused while doing blocking operations like that.

`Notify` uses `Promise`s so it’s better suited for concurrency. The
`Task` is not blocked while waiting for a notification which makes it
simpler for use cases that just involve notifying:

```lean
def notify : Async Unit := do
  let notify ← Std.Notify.new

  for i in [0:threads] do
    background do
      IO.println s!"start {i}"
      notify.wait
      IO.println s!"end {i}"

  IO.sleep 2000
  notify.notify
```

This PR depends on: #10366, #10367 and #10370.
github-merge-queue bot pushed a commit that referenced this pull request Oct 6, 2025
This PR adds a multi-consumer, multi-producer channel to Std.Sync.

This PR depends on: #10366, #10367 and #10370.

---------

Co-authored-by: Markus Himmel <markus@lean-fro.org>
github-merge-queue bot pushed a commit that referenced this pull request Oct 7, 2025
This PR adds the StreamMap type that enables multiplexing in
asynchronous streams.

This PR depends on: #10366, #10367 and #10370.

---------

Co-authored-by: Markus Himmel <markus@lean-fro.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-library Library toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants