zio icon indicating copy to clipboard operation
zio copied to clipboard

Async File Systems

Open Nikey646 opened this issue 4 years ago • 5 comments

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

Nikey646 avatar Oct 31 '20 12:10 Nikey646

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.

xoofx avatar Nov 07 '20 07:11 xoofx

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?

Nikey646 avatar Nov 09 '20 00:11 Nikey646

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.

xoofx avatar Nov 27 '20 06:11 xoofx

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.

GerardSmit avatar Oct 28 '22 14:10 GerardSmit

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.

xoofx avatar Oct 28 '22 16:10 xoofx