Skip to content

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