feat: add opt-in block_on executor - #153
Open
jiengup wants to merge 1 commit into
Open
Conversation
Provide a minimal single-future blocking executor behind the block_on Cargo feature, with block_on, block_on_timeout, and FutureExt methods.
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.
Summary
Adds an opt-in
asyncband::block_onmodule for synchronous code that needs to wait on a single runtime-agnostic future without pulling in a full async runtime.Motivation
Closes #147.
asyncbanddeliberately keeps the default API runtime-agnostic, so users currently have to depend on a separate executor just to block on operations such asMutex::lock. This PR adds a lightweight bridge while leaving the default API and dependency tree unchanged.Approach
block_onCargo feature, disabled by default. It is an empty feature, so the default build gains no dependencies.asyncband::block_onwith:block_on(fut)— runs anIntoFutureto completion while parking the current thread.block_on_timeout(fut, timeout)— deadline-bounded variant usingthread::park_timeout.FutureExt— suffix-style.block_on()and.block_on_timeout(timeout).Timeout— error returned when the deadline is reached and the future is cancelled.API
Documentation
Module docs clarify that:
block_on_timeoutis a wall-clock bailout for the outer blocking loop, not a timer context for the future itself.Tests
Added coverage for ready futures, suffix-style calls, cross-thread wake-ups, timeout behavior, zero timeouts, and cancellation of a timed-out
Mutex::lock.cargo x testnow enables theblock_onfeature so these tests run in CI.