Mossaka / client-node

3 stars 1 forks source link

Completely get rid of `queue.send` block in `transaction.rs` and `raw.rs` #14

Closed Mossaka closed 3 years ago

Mossaka commented 3 years ago

They should move to utils.rs as much as possible to reduce code noise.

Mossaka commented 3 years ago

One example that I really want to get rid of is the Transaction::get_for_update:

let value = inner.lock().await.get_for_update(key).await.unwrap(); //TODO: this is a wrong implementation
queue.send(move |mut cx| {
    let callback = callback.into_inner(&mut cx);
    let this = cx.undefined();
    let args: Vec<Handle<JsValue>> = match value {
        Some(content) => {
            // let js_array = JsArray::new(&mut cx, content.len() as u32);
            // for (i, obj) in content.iter().enumerate() {
            //     let js_string = cx.number(*obj as f64);
            //     js_array.set(&mut cx, i as u32, js_string).unwrap();
            // }
            // vec![cx.undefined().upcast(), js_array.upcast()]

            vec![cx.null().upcast(), bytes_to_js_string(&mut cx, content)]
        }
        None => vec![cx.null().upcast(), cx.undefined().upcast()],
    };
    callback.call(&mut cx, this, args)?;
    Ok(())
});