Merge pull request #109 from Mike-Dax/threadsafe-function-documentation
Fixed documentation of threadsafe functions
This commit is contained in:
commit
64510ec90f
1 changed files with 10 additions and 6 deletions
|
@ -45,12 +45,14 @@ pub trait ToJs: Copy + Clone {
|
|||
///
|
||||
/// impl ToJs for HandleNumber {
|
||||
/// type Output = u8;
|
||||
/// type JsValue = JsNumber;
|
||||
///
|
||||
/// fn resolve(&self, env: &mut Env, output: Self::Output) -> Result<(u64, Self::JsValue)> {
|
||||
/// let argv: u64 = 1;
|
||||
/// let value = env.create_uint32(output as u32)?;
|
||||
/// Ok((argv, value))
|
||||
/// fn resolve(&self, env: &mut Env, output: Self::Output) -> Result<Vec<JsUnknown>> {
|
||||
/// let value = env.create_uint32(output as u32)?.into_unknown()?;
|
||||
/// // The first argument in the NodeJS callback will be either a null or an error
|
||||
/// // depending on the result returned by this function.
|
||||
/// // If this Result is Ok, the first argument will be null.
|
||||
/// // If this Result is Err, the first argument will be the error.
|
||||
/// Ok(vec![value])
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
|
@ -202,7 +204,9 @@ unsafe extern "C" fn call_js_cb<T: ToJs>(
|
|||
|
||||
let status;
|
||||
|
||||
// Follow the convention of Node.js async callback.
|
||||
// Follow async callback conventions: https://nodejs.org/en/knowledge/errors/what-are-the-error-conventions/
|
||||
// Check if the Result is okay, if so, pass a null as the first (error) argument automatically.
|
||||
// If the Result is an error, pass that as the first argument.
|
||||
if ret.is_ok() {
|
||||
let values = ret.unwrap();
|
||||
let js_null = env.get_null().unwrap();
|
||||
|
|
Loading…
Reference in a new issue