[WIP] Async-ify fetching content-addressed uri contents#166
Open
njgheorghita wants to merge 2 commits intoethpm:masterfrom
Open
[WIP] Async-ify fetching content-addressed uri contents#166njgheorghita wants to merge 2 commits intoethpm:masterfrom
njgheorghita wants to merge 2 commits intoethpm:masterfrom
Conversation
Member
pipermerriam
left a comment
There was a problem hiding this comment.
I think we can do this without re-implementing each endpoint. I recently realized that this allows for both sync and async implementations of an ABC method.
@abstractmethod
def fetch_uri_contents(self, uri: URI) -> Union[Union[bytes, URI], Awaitable[Union[bytes, URI]]]:
"""
Fetch the contents stored at a URI.
"""
passIt's a little tricky and I'm not 100% sure about it as a pattern yet but it would allow you to do something like this which sniffs each method and calls them appropriately.
async resolve_all_the_things(backend, uri):
if asyncio.iscoroutinefunction(backend.fetch_uri_concents):
return await backend.fetch_uri_contents(uri)
else:
return await trio.run_sync_in_worker_thread(backend.fetch_uri_contents, uri)cc @cburgdorf who might have some opinions about this approach.
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.
What was wrong?
It would be nice to fetch multiple ipfs assets with an async strategy, using all the available ipfs backends.
Still very WIP/experimental - lot's of cleanup / tests to write, but just looking for general feedback on the api / implementing trio
Cute Animal Picture