alef 0.24.13

Opinionated polyglot binding generator for Rust libraries
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
type TraitReplySender = tokio::sync::oneshot::Sender<String>;
type TraitReplyMap = Mutex<HashMap<u64, TraitReplySender>>;

static TRAIT_REPLY_MAP: OnceLock<TraitReplyMap> = OnceLock::new();

fn trait_reply_map() -> &'static TraitReplyMap {
    TRAIT_REPLY_MAP.get_or_init(|| Mutex::new(HashMap::new()))
}

/// Complete a pending trait call with the JSON response from Elixir.
#[rustler::nif]
pub fn complete_trait_call(reply_id: u64, response_json: String) -> Atom {
    if let Some(tx) = trait_reply_map().lock().unwrap().remove(&reply_id) {
        let _ = tx.send(response_json);
    }
    atoms::ok()
}