Repository navigation
feat(async): [breaking] align future API with copas.future - #6
Merged
Merged
Conversation
Tieske
commented
Mar 26, 2026
Owner
- get() now returns pcall-style: true+results on success, false+errmsg on error
- try() now returns 3-state: PENDING(false)/SUCCESS(true)/ERROR('error') with results
- Replace assert-on-concurrent-access with copas.semaphore; multiple coroutines can now call get() concurrently and all are released when the result arrives
- Wrap fn() in pcall in the Lanes thread so task errors are captured and returned via get()/try() instead of being silently lost
- Add SUCCESS, PENDING, ERROR constants to the module (matching copas.future)
- Add module __index guard that errors on unknown field names (typo protection)
- Update io_popen internals: prepend true ok-flag in awake_future calls, strip it with select(2,...) on the consumer side
- Replace deprecated copas.sleep(-1) with copas.pauseforever()
Tieske
force-pushed
the
feat/align-future-api
branch
2 times, most recently
from
March 27, 2026 12:09
54aa0f9 to
53025eb
Compare
- get() now returns pcall-style: true+results on success, false+errmsg on error
- try() now returns 3-state: PENDING(false)/SUCCESS(true)/ERROR('error') with results
- Replace assert-on-concurrent-access with copas.semaphore; multiple coroutines
can now call get() concurrently and all are released when the result arrives
- Wrap fn() in pcall in the Lanes thread so task errors are captured and
returned via get()/try() instead of being silently lost
- Add SUCCESS, PENDING, ERROR constants to the module (matching copas.future)
- Add module __index guard that errors on unknown field names (typo protection)
- Update io_popen internals: prepend true ok-flag in awake_future calls,
strip it with select(2,...) on the consumer side
- Replace deprecated copas.sleep(-1) with copas.pauseforever()
In busted, _G.unpack is overridden with a non-transferable function. Introduce _G._TEST flag (set in before_each, cleared in after_each) to switch to a pure recursive unpack with no external upvalues, which Lanes can safely transfer to OS threads on any Lua version.
Tieske
force-pushed
the
feat/align-future-api
branch
from
March 27, 2026 17:30
53025eb to
54eb1d8
Compare
Adds future:cancel() matching the copas.future API. Cancels the Lanes thread (best-effort), releases any coroutine blocked in get() via the wakeup mechanism, and releases semaphore waiters. The lane is now passed into new_future as a parameter rather than set on the future afterwards.
Adds future:cancel() matching the copas.future API. The Copas side is always cancelled immediately: results are set to "cancelled", any coroutine blocked in get() is woken via the wakeup mechanism, and semaphore waiters are released. The underlying Lanes thread is soft-cancelled first. If it is still running after async.cancel_timeout seconds (default 5s, e.g. when blocked in a C call like socket.sleep), it is force-killed via pcall(lane:cancel, lane, 0, true). cancel() also checks the Linda for an already-arrived result before deciding to cancel, so it correctly returns false when the thread has finished even if get()/try() was never called. Tests cover: cancel while pending, cancel after done, cancel releasing a blocked get(), and the force-kill firing after cancel_timeout.
Fix os_execute call in example.lua to capture the pcall-style ok flag. Update the expected output block to match actual output. Rewrite example-popen.lua to uncomment and clean up the examples, replacing socket.sleep with copas.sleep and adding descriptive comments.
Tieske
force-pushed
the
feat/align-future-api
branch
from
March 27, 2026 17:44
cf88614 to
fe1ce97
Compare
Tieske
force-pushed
the
feat/align-future-api
branch
from
March 27, 2026 17:46
fe1ce97 to
669f837
Compare
Tieske
marked this pull request as ready for review
March 27, 2026 17:47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.