fn complete(
        self,
        mut cx: TaskContext,
        event: Result<Self::Output, Self::Error>,
    ) -> JsResult<Self::JsEvent> {
        // Receive the event or return early with the error
        let event = event.or_else(|err| cx.throw_error(&err.to_string()))?;

        // Timeout occured, return early with `undefined
        let event = match event {
            Some(event) => event,
            None => return Ok(JsUndefined::new().upcast()),
        };

        // Create an empty object `{}`
        let o = cx.empty_object();

        // Creates an object of the shape `{ "event": string, ...data }`
        match event {
            Event::Error { message, stack } => {
                let event_name = cx.string("error");
                let event_message = cx.string(message);
                let event_stack = cx.string(stack);

                o.set(&mut cx, "event", event_name)?;
                o.set(&mut cx, "message", event_message)?;
                o.set(&mut cx, "stack", event_stack)?;
            }
            Event::StateChanged { state } => {
                let event_name = cx.string("stateChanged");
                let event_state = cx.string(format!("{:?}", state).to_string());

                o.set(&mut cx, "event", event_name)?;
                o.set(&mut cx, "state", event_state)?;
            }
            Event::Eos {} => {
                let event_name = cx.string("eos");

                o.set(&mut cx, "event", event_name)?;
            }
        }

        Ok(o.upcast())
    }
/// After the `perform` method has returned, the `complete` method is
/// scheduled on the main thread. It is responsible for converting the
/// Rust data structure into a JS object.
After the `perform` method has returned, the `complete` method is
scheduled on the main thread. It is responsible for converting the
Rust data structure into a JS object.
After the ` perform ` method has returned the ` complete ` method is scheduled on the main thread . It is responsible for converting the Rust data structure into a JS object .
fn complete(
        self,
        mut cx: TaskContext,
        event: Result<Self::Output, Self::Error>,
    ) -> JsResult<Self::JsEvent> {
        // Receive the event or return early with the error
        let event = event.or_else(|err| cx.throw_error(&err.to_string()))?;
        // Timeout occured, return early with `undefined
        let event = match event {
            Some(event) => event,
            None => return Ok(JsUndefined::new().upcast()),
        };
        // Create an empty object `{}`
        let o = cx.empty_object();
        // Creates an object of the shape `{ "event": string, ...data }`
        match event {
            Event::Error { message, stack } => {
                let event_name = cx.string("error");
                let event_message = cx.string(message);
                let event_stack = cx.string(stack);
                o.set(&mut cx, "event", event_name)?;
                o.set(&mut cx, "message", event_message)?;
                o.set(&mut cx, "stack", event_stack)?;
            }
            Event::StateChanged { state } => {
                let event_name = cx.string("stateChanged");
                let event_state = cx.string(format!("{:?}", state).to_string());
                o.set(&mut cx, "event", event_name)?;
                o.set(&mut cx, "state", event_state)?;
            }
            Event::Eos {} => {
                let event_name = cx.string("eos");
                o.set(&mut cx, "event", event_name)?;
            }
        }
        Ok(o.upcast())
    }
fn complete ( self , mut cx : TaskContext , event : Result < Self :: Output , Self :: Error > , ) -> JsResult < Self :: JsEvent > { // Receive the event or return early with the error let event = event . or_else ( | err | cx . throw_error ( & err . to_string ( ) ) ) ? ; // Timeout occured, return early with `undefined let event = match event { Some ( event ) => event , None => return Ok ( JsUndefined :: new ( ) . upcast ( ) ) , } ; // Create an empty object `{}` let o = cx . empty_object ( ) ; // Creates an object of the shape `{ "event": string, ...data }` match event { Event :: Error { message , stack } => { let event_name = cx . string ( " " ) ; let event_message = cx . string ( message ) ; let event_stack = cx . string ( stack ) ; o . set ( & mut cx , " " , event_name ) ? ; o . set ( & mut cx , " " , event_message ) ? ; o . set ( & mut cx , " " , event_stack ) ? ; } Event :: StateChanged { state } => { let event_name = cx . string ( " " ) ; let event_state = cx . string ( format ! ( " " state ) . to_string ( ) ) ; o . set ( & mut cx , " " , event_name ) ? ; o . set ( & mut cx , " " , event_state ) ? ; } Event :: Eos { } => { let event_name = cx . string ( " " ) ; o . set ( & mut cx , " " , event_name ) ? ; } } Ok ( o . upcast ( ) ) }
After the `perform` method has returned, the `complete` method is
scheduled on the main thread.
After the ` perform ` method has returned the ` complete ` method is scheduled on the main thread .
self
cx
TaskContext
event
Result<Self::Output, Self::Error>
self
cx
TaskContext
event
Result<Self::Output, Self::Error>