fn async_import(&self, caller: Caller, ptr: u32, len: u32) -> Result<u32, Trap> {
    // 1) Extract the method name and arguments from memory.
    let args = self.extract_args(ptr as usize, len as usize)?;
    // 2) Call the threadsafe request function with the args.
    self
      .req
      .call(
        Ok(Request { mid: self.id, args }),
        ThreadsafeFunctionCallMode::Blocking,
      )
      .map_err(|e| Trap::new(format!("Request failed: {}", e)))?;
    // 3) The response will be sent through the channel, so block on it.
    let rsp = match self.rx.recv() {
      Ok(MachineMessage::Response(ResponseMessage::Success(rsp))) => Ok(rsp),
      Ok(MachineMessage::Response(ResponseMessage::Failure(err))) => Err(err),
      _ => Err(anyhow!(
        "Invalid message received when response was expected"
      )),
    }?;
    // 4) Write the return value into wasm memory.
    let res_ptr = self.write_buffer(rsp, true)?;
    Ok(res_ptr as u32)
  }
// All async importers take a (ptr, len) pair for the args, then return a ptr to the result bytes (varint length prefixed).
All async importers take a (ptr, len) pair for the args, then return a ptr to the result bytes (varint length prefixed).
All async importers take a ( ptr len ) pair for the args then return a ptr to the result bytes ( varint length prefixed ) .
fn async_import(&self, caller: Caller, ptr: u32, len: u32) -> Result<u32, Trap> {
    // 1) Extract the method name and arguments from memory.
    let args = self.extract_args(ptr as usize, len as usize)?;
    // 2) Call the threadsafe request function with the args.
    self
      .req
      .call(
        Ok(Request { mid: self.id, args }),
        ThreadsafeFunctionCallMode::Blocking,
      )
      .map_err(|e| Trap::new(format!("Request failed: {}", e)))?;
    // 3) The response will be sent through the channel, so block on it.
    let rsp = match self.rx.recv() {
      Ok(MachineMessage::Response(ResponseMessage::Success(rsp))) => Ok(rsp),
      Ok(MachineMessage::Response(ResponseMessage::Failure(err))) => Err(err),
      _ => Err(anyhow!(
        "Invalid message received when response was expected"
      )),
    }?;
    // 4) Write the return value into wasm memory.
    let res_ptr = self.write_buffer(rsp, true)?;
    Ok(res_ptr as u32)
  }
fn async_import ( & self , caller : Caller , ptr : u32 , len : u32 ) -> Result < u32 , Trap > { // 1) Extract the method name and arguments from memory. let args = self . extract_args ( ptr as usize , len as usize ) ? ; // 2) Call the threadsafe request function with the args. self . req . call ( Ok ( Request { mid : self . id , args } ) , ThreadsafeFunctionCallMode :: Blocking , ) . map_err ( | e | Trap :: new ( format ! ( " " e ) ) ) ? ; // 3) The response will be sent through the channel, so block on it. let rsp = match self . rx . recv ( ) { Ok ( MachineMessage :: Response ( ResponseMessage :: Success ( rsp ) ) ) => Ok ( rsp ) , Ok ( MachineMessage :: Response ( ResponseMessage :: Failure ( err ) ) ) => Err ( err ) , _ => Err ( anyhow ! ( " " ) ) , } ? ; // 4) Write the return value into wasm memory. let res_ptr = self . write_buffer ( rsp , true ) ? ; Ok ( res_ptr as u32 ) }
All async importers take a (ptr, len) pair for the args, then return a ptr to the result bytes (varint length prefixed).
All async importers take a ( ptr len ) pair for the args then return a ptr to the result bytes ( varint length prefixed ) .
&self
caller
Caller
ptr
u32
len
u32
&self
caller
Caller
ptr
u32
len
u32