Skip to content

Commit

Permalink
fix: ts side of error callback now know how to handle err
Browse files Browse the repository at this point in the history
fix: error array index skipping
  • Loading branch information
kgmyatthu authored and mhanson-github committed Aug 15, 2024
1 parent 5273429 commit 0131136
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 4 additions & 2 deletions shardus_net/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,15 @@ pub fn multi_send_with_header(mut cx: FunctionContext) -> JsResult<JsUndefined>
nodejs_thread_channel.send(move |mut cx| {
let cx = &mut cx;

let stats = this.to_inner(cx).get::<JsBox<RefCell<Stats>>, _, _>(cx, "_stats")?;
let js_arr = cx.empty_array();
let mut error_count = 0;
for i in 0..results.len() {
let stats = this.to_inner(cx).get::<JsBox<RefCell<Stats>>, _, _>(cx, "_stats")?;
(**stats).borrow_mut().decrement_outstanding_sends();
if let Err(err) = &results[i] {
let err = cx.string(format!("{:?}", err));
js_arr.set(cx, i as u32, err)?;
js_arr.set(cx, error_count, err)?;
error_count += 1;
}
}

Expand Down
17 changes: 14 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,22 @@ export const Sn = (opts: SnOpts) => {
: null
/* prettier-ignore */ if(logFlags.net_verbose) logMessageInfo(augData, stringifiedData)

const sendCallback = (error) => {
const multiSendCallback = (error: string[]) => {
if (error.length == address.length) {
throw new Error(`_sendAug: request_id: ${augData.UUID} error sending from rust failure lib-net: ${error.join(', ')}`)
}
if (error.length > 0) {
return resolve({ success: false, error: error.join(', ') })
}
return resolve({ success: true })
}

const sendCallback = (error?: string) => {
if (error) {
resolve({ success: false, error })
} else {
}else {
resolve({ success: true })

}
}
try {
Expand All @@ -167,7 +178,7 @@ export const Sn = (opts: SnOpts) => {
optionalHeader.version,
stringifiedHeader,
stringifiedData,
sendCallback,
multiSendCallback,
callbackEnabled
)
} else {
Expand Down

0 comments on commit 0131136

Please sign in to comment.