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

[WIP] Async-ify fetching content-addressed uri contents #166

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

njgheorghita
Copy link
Contributor

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

Cute animal picture

Copy link
Member

@pipermerriam pipermerriam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
        """
        pass

It'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.

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