Kriskras99 commented on code in PR #238:
URL: https://github.com/apache/avro-rs/pull/238#discussion_r2225791048


##########
rfc.md:
##########
@@ -0,0 +1,88 @@
+# Possible implementations
+
+## Maintaining two separate implementations
+
+Pros:
+ - Easy to implement (just copy-paste the blocking implementation and start 
inserting `async`/`await`)
+ - Allows for optimal performance in both situations
+ - *Should* be able to share at least a part of the implementation
+
+Cons:
+ - Maintenance, any bug needs to be fixed in both implementations. Same goes 
for testing.
+ - Hard to onboard, new contributors will be confronted with a very large 
codebase (see [Good ol' 
copy-pasting](https://nullderef.com/blog/rust-async-sync/#good-ol-copy-pasting))
+ - Adding new functionality means implementing it twice.
+
+## Implement in async, use `block_on` for sync implementation
+
+In this implementation, the core codebase is implemented asynchronously. A 
`blocking` module is provided which wraps
+the async functions/types in `block_on` calls. Recreating the runtime on every 
call is very slow, so to make this work
+it would involve spawning a thread for the runtime and using that to spawn the 
async functions. This is how `reqwest`
+implements their async/sync code.
+
+Pros:
+ - Only need to maintain/test/upgrade one implementation
+ - Optimal performance for async code
+
+Cons:
+ - Degrades sync performance
+ - Need to pull in a runtime when the `blocking` feature is enabled (`reqwest` 
use `tokio` but something like `smoll` might make more sense)
+
+## Implement in async, use `maybe_async` to generate sync implementation
+
+[`maybe_async`](https://crates.io/crates/maybe-async) is a proc macro that 
removes the `.await` from the async code and uses it to generate sync code.
+
+Pros:
+ - Only need to maintain/test/upgrade one implementation
+ - Optimal performance for both async and sync code
+
+Cons:
+ - Crate breaks if both the `sync` and `async` features are enabled

Review Comment:
   ```suggestion
   [`maybe_async`](https://crates.io/crates/maybe-async) is a proc macro that 
removes the `.await` from the async code and uses it to generate sync code. 
[`synca`](https://docs.rs/synca/latest/synca/) is another option where both 
sync and async code can coexist.
   
   Pros:
    - Only need to maintain/test/upgrade one implementation
    - Optimal performance for both async and sync code
   
   Cons:
    - Crate breaks if both the `sync` and `async` features are enabled (only 
for `maybe_async`)
    - `synca` hasn't seen an update in more than a year, but seems to be 
feature complete
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to