assert_eq!(data.len(), 0);
// Decode the message as RandRange
let inner = base.inner_as_rand_range().unwrap();
// Get the command id, used to respond to async calls
let cmd_id = base.cmd_id();
// Get `from` and `to` out of the buffer
// Wrap our potentially slow code and respond code here
// Based on dispatch.sendSync and dispatch.sendAsync,
// base.sync() will be true or false.
// If true, blocking() will spawn the task on the main thread
// Else, blocking() would spawn it in the Tokio thread pool
blocking(base.sync(), move || -> OpResult {
// Actual random number generation code!
let result = thread_rng().gen_range(from, to);
// Prepare respond message serialization
// Treat these as boilerplate code for now
let builder = &mut FlatBufferBuilder::new();
// We want the message type to be RandRangeRes
let inner = msg::RandRangeRes::create(
result, // put in our result here
// Get message serialized
cmd_id, // Used to reply to TypeScript if this is an async call
inner: Some(inner.as_union_value()),
inner_type: msg::Any::RandRangeRes,