xoofx / zio

A cross-platform abstract/virtual filesystem framework with many built-ins filesystems for .NET
BSD 2-Clause "Simplified" License
806 stars 61 forks source link

Async File Systems #53

Open Nikey646 opened 3 years ago

Nikey646 commented 3 years ago

Is there any plans to allow the implementation of Async File Systems, EG: Azure Blob?

xoofx commented 3 years ago

No plan, as I don't have a personal use for this feature. but It is definitely possible to bring support for async. It would require to duplicate the interface and implement all the Async methods. It's a bit of work, but should not be too difficult. PR welcome.

Nikey646 commented 3 years ago

When looking at the IFileSystem interface, would you want every method to have an Async counter part?

When adding to the existing implementations, would you rather just call Task.FromResult(SyncImpl());?

When the implementation only provides a Async implementations (All of the files are in Azure Blob), should the Sync methods just call the Async methods with .GetAwaiter().GetResult() to make the execution occur in the current thread?

xoofx commented 3 years ago

Ooops, sorry to get back to you only now, I thought I responded immediately.

When looking at the IFileSystem interface, would you want every method to have an Async counter part?

I would believe.

When adding to the existing implementations, would you rather just call Task.FromResult(SyncImpl());?

Yes, except that all methods should return a ValueTask instead.

When the implementation only provides a Async implementations (All of the files are in Azure Blob), should the Sync methods just call the Async methods with .GetAwaiter().GetResult() to make the execution occur in the current thread?

Likely yes.

GerardSmit commented 1 year ago

FYI: Someone made source generator that generates sync methods from async methods; https://github.com/zompinc/sync-method-generator. It's the other away around for Zio, so it would still require a lot of refactoring to async methods (what Sébastien did in https://github.com/xoofx/zio/pull/62) but it would remove the need for duplicated code.

xoofx commented 1 year ago

Yep, I tried to reuse the technique I used for Generate automatically async/await code from sync code with Roslyn that I'm using for another project, but as the generator was specific to the library, I took some shortcuts and so it's not reusable as it is. Would take quite some time to make it working, possible, but time costly.