Skip to content

Commit

Permalink
Merge pull request #12 from akiles/android-channel
Browse files Browse the repository at this point in the history
android: switch from futures-channel to async-channel.
  • Loading branch information
alexmoon authored Mar 20, 2024
2 parents 359c026 + b0af343 commit b91fd32
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ tokio = { version = "1.20.1", features = ["rt-multi-thread"] }

[target.'cfg(target_os = "android")'.dependencies]
java-spaghetti = "0.1.0"
futures-channel = "0.3.24"
async-channel = "2.2.0"

[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
async-broadcast = "0.5.1"
Expand Down
8 changes: 4 additions & 4 deletions src/android/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::atomic::{AtomicI32, Ordering};
use std::sync::{Arc, Mutex};
use std::task::{Context, Poll};

use futures_channel::mpsc::{Receiver, Sender};
use async_channel::{Receiver, Sender};
use futures_core::Stream;
use futures_lite::{stream, StreamExt};
use java_spaghetti::{Arg, ByteArray, Env, Global, Local, PrimitiveArray, VM};
Expand Down Expand Up @@ -96,7 +96,7 @@ impl AdapterImpl {
});
});

Ok(receiver.map(move |x| {
Ok(Box::pin(receiver).map(move |x| {
let _guard = &guard;
x
}))
Expand Down Expand Up @@ -174,7 +174,7 @@ impl<T: Send + 'static> CallbackRouter<T> {

fn allocate(&'static self) -> CallbackReceiver<T> {
let id = self.next_id.fetch_add(1, Ordering::Relaxed);
let (sender, receiver) = futures_channel::mpsc::channel(16);
let (sender, receiver) = async_channel::bounded(16);
self.map
.lock()
.unwrap()
Expand All @@ -190,7 +190,7 @@ impl<T: Send + 'static> CallbackRouter<T> {

fn callback(&'static self, id: i32, val: T) {
if let Some(sender) = self.map.lock().unwrap().as_mut().unwrap().get_mut(&id) {
if let Err(e) = sender.try_send(val) {
if let Err(e) = sender.send_blocking(val) {
warn!("failed to send scan callback: {:?}", e)
}
}
Expand Down

0 comments on commit b91fd32

Please sign in to comment.