Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring serial API in line with async using requests-futures #37

Merged
merged 1 commit into from
Sep 9, 2024

Conversation

arahlin
Copy link
Contributor

@arahlin arahlin commented Sep 9, 2024

This PR rearranges the SimpleContext object to use a FuturesSession for dispatching HTTP requests to a thread pool, rather than waiting for them to complete on the main thread. This brings the API for the SimpleContext object in line with that of the async Context object. TuberObject methods are executed serially without await, and context methods return a Future whose result() method returns the corresponding result from the server. Calling a context directly blocks until it responds, akin to the await ctx() API of the async Context.

To allow for asynchronous communication with several servers, the (non-blocking) SimpleContext.send() method returns a Future object whose (blocking) result() method contains the full requests.Response object as processed from the server. The SimpleContext.receive() method can then be used to block and return the results of each method executed on the server.

This PR rearranges the `SimpleContext` object to use a `FuturesSession` for
dispatching HTTP requests to a thread pool, rather than waiting for them to
complete on the main thread.  This brings the API for the `SimpleContext` object
in line with that of the async `Context` object.  `TuberObject` methods are
executed serially without `await`, and context methods return a `Future` whose
`result()` method returns the corresponding result from the server.  Calling a
context directly blocks until it responds, akin to the `await ctx()` API of the
async `Context`.

To allow for asynchronous communication with several servers, the (non-blocking)
`SimpleContext.send()` method returns a `Future` object whose (blocking)
`result()` method contains the full `requests.Response` object as processed from
the server.  The `SimpleContext.receive()` method can then be used to block and
return the results of each method executed on the server.
@gsmecher gsmecher merged commit e4a9e9b into gsmecher:master Sep 9, 2024
7 checks passed
@arahlin arahlin deleted the requests_futures branch September 9, 2024 23:05
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.

2 participants