Skip to content

Commit

Permalink
Use the oneshot library for one-shot futures
Browse files Browse the repository at this point in the history
`oneshot` handles one of our main use-cases with futures: a future
that's completed by manually sending the result over one-shot channel.
This replaces the `RunFuture` code and I hope to also use it for async
callback interface methods.

`oneshot` seems like a reasonable dependency to add.  It's small,
fairly popular, and replaces a lot of messy code.

I doubt the performance matters, but FWIW I think it should perform much
better than my naive mutex-based implementation for sending/receiving
the value.  We do lose one optimization: `RunFuture` stored the closure
alongside the rest of the future internals which meant one less heap
allocation.  However, even that optimization comes at the cost of not
being able to free the closure memory until the future was awaited and
dropped by the consumer.  Overall this seems like a win.
  • Loading branch information
bendk committed Aug 29, 2023
1 parent 95c1be6 commit d4a6e65
Show file tree
Hide file tree
Showing 3 changed files with 258 additions and 142 deletions.
199 changes: 194 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions uniffi_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ async-compat = { version = "0.2.1", optional = true }
bytes = "1.3"
camino = "1.0.8"
log = "0.4"
once_cell = "1.12"
# Enable "async" so that receivers implement Future, no need for "std" since we don't block on them.
oneshot = { version = "0.1", features = ["async"] }
# Regular dependencies
cargo_metadata = "0.15"
paste = "1.0"
static_assertions = "1.1.0"

Expand Down
Loading

0 comments on commit d4a6e65

Please sign in to comment.