jj/cli/examples
Martin von Zweigbergk b970939804 backend: make read_file() return a AsyncRead
The `Backend::read_file()` method is async but it returns a `Box<dyn
Read>` and reading from that trait is blocking. That's fine with the
local Git backend but it can be slow for remote backends. For example,
our backend at Google reads file chunks 1 MiB at a time from the
server. What that means is that reading lots of small files
concurrently works fine since the whole file contents are returned by
the first `Read::read()` call (it was fetched when
`Backend::read_file()` was issued). However, when reading files that
are larger than one chunk, we end up blocking on the next
`Read::read()` call. I haven't verified that this actually is a
problem at Google, but fixing this blocking is something we should do
eventually anyway.

This patch makes `Backend::read_file()` return a `Pin<Box<dyn
AsyncRead>>` instead, so implementations can be async in the read part
too.

Since `AsyncRead` is not yet standardized, we have to choose between
the one from `futures` and the one from `tokio`. I went with the one
from `tokio`. I picked that because an earlier version of this patch
used `tokio::fs` for some reads. Then I realized that doing that means
that we have to use a tokio runtime, meaning that we can't safely keep
our existing `pollster::FutureExt::block_on()` calls. If we start
depending on tokio's specific runtime, I think we would first want to
remove all the `block_on()` calls. I'll leave that for later. I think
at this point, we could equally well use `futures::io::AsyncRead`, but
I also don't know if there's a reason to prefer that.
2025-05-20 13:23:36 +00:00
..
custom-backend backend: make read_file() return a AsyncRead 2025-05-20 13:23:36 +00:00
custom-command cli: replace ExitCode by u8 2025-05-17 05:45:59 +00:00
custom-commit-templater cli: replace ExitCode by u8 2025-05-17 05:45:59 +00:00
custom-global-flag cli: replace ExitCode by u8 2025-05-17 05:45:59 +00:00
custom-operation-templater cli: replace ExitCode by u8 2025-05-17 05:45:59 +00:00
custom-working-copy cli: replace ExitCode by u8 2025-05-17 05:45:59 +00:00