Skip to content

Rework fibres runtime for coroutine-safe errors, scopes, and channel/waitgroup semantics - #56

Merged
lePereT merged 8 commits into
nextfrom
update_primitives
Nov 17, 2025
Merged

lePereT merged 8 commits into
nextfrom
update_primitives

Conversation

@lePereT

@lePereT lePereT commented Nov 17, 2025

Copy link
Copy Markdown
Contributor

What type of PR is this? (check all applicable)

  • Bug Fix
  • Code Refactor
  • Test

Description

Reworks the fibres runtime to be exception-neutral, coroutine-safe, and aligned with structured concurrency semantics.

  • Introduces a local coxpcall shim providing coroutine-safe pcall/xpcall and coroutine.running semantics.

  • Changes fibers.runtime to route uncaught fiber errors through an internal queue and wait_fiber_error, rather than aborting the process.

  • Refactors fibers.scope to:

    • supervise fibers via the runtime error queue,
    • make scope.run return (status, error, ...) instead of raising,
    • enforce that Scope:spawn only runs on a running scope,
    • drive scope closure, defers and status changes via a join worker.
  • Simplifies fibers.op:

    • removes wrap_handler and exception-based control flow,
    • makes events exception-neutral and adds or_else, finally, bracket and higher-level choice helpers (race, first_ready, named_choice, boolean_choice),
    • adjusts new_cond and nack signalling to run via the scheduler and coxpcall.
  • Reworks fibers.channel to:

    • track per-operation entries and support cancellation via on_abort,
    • skip cancelled senders/receivers when matching operations.
  • Reimplements fibers.waitgroup with per-generation conditions so waitgroups can be reused safely.

  • Tightens fibers.performer.perform with an explicit Event metatable check.

  • Extends syscall errno exports with EBADF and ENOENT.

  • Updates tests (test_channel, test_cond, test_op, test_scope, test_waitgroup) to reflect the new semantics and add coverage for waitgroup reuse and scope cancellation paths.

Manual test

  • yes

Manual test description

Ran the Lua test suite locally. All completed without failures.

Added tests?

  • yes

Added to documentation?

  • no documentation needed

@lePereT
lePereT changed the base branch from main to next November 17, 2025 02:56
@lePereT
lePereT merged commit ba83096 into next Nov 17, 2025
1 check passed
@lePereT
lePereT deleted the update_primitives branch November 17, 2025 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant