fn compute<F, R>(&self, func: F) -> Result<ComputeTask<R>, FreeRtosError>
    where
        F: FnOnce() -> R,
        F: Send + 'static,
        R: Sync + Send + 'static,
    {
        let (task, result, status) = {
            let result = Arc::new(Mutex::new(None)?);
            let status = Arc::new(Queue::new(1)?);

            let task_result = result.clone();
            let task_status = status.clone();
            let task = self.start(move |_this_task| {
                {
                    let mut lock = task_result.lock(Duration::infinite()).unwrap();
                    let r = func();
                    *lock = Some(r);
                }
                // release our reference to the mutex, so it can be deconstructed
                drop(task_result);
                task_status
                    .send(ComputeTaskStatus::Finished, Duration::infinite())
                    .unwrap();
            })?;

            (task, result, status)
        };

        Ok(ComputeTask {
            task: task,
            result: result,
            status: status,
            finished: false,
        })
    }
/// Spawn a task that can post a return value to the outside.
Spawn a task that can post a return value to the outside.
Spawn a task that can post a return value to the outside .
fn compute<F, R>(&self, func: F) -> Result<ComputeTask<R>, FreeRtosError>
    where
        F: FnOnce() -> R,
        F: Send + 'static,
        R: Sync + Send + 'static,
    {
        let (task, result, status) = {
            let result = Arc::new(Mutex::new(None)?);
            let status = Arc::new(Queue::new(1)?);
            let task_result = result.clone();
            let task_status = status.clone();
            let task = self.start(move |_this_task| {
                {
                    let mut lock = task_result.lock(Duration::infinite()).unwrap();
                    let r = func();
                    *lock = Some(r);
                }
                // release our reference to the mutex, so it can be deconstructed
                drop(task_result);
                task_status
                    .send(ComputeTaskStatus::Finished, Duration::infinite())
                    .unwrap();
            })?;
            (task, result, status)
        };
        Ok(ComputeTask {
            task: task,
            result: result,
            status: status,
            finished: false,
        })
    }
fn compute < F , R > ( & self , func : F ) -> Result < ComputeTask < R > , FreeRtosError > where F : FnOnce ( ) -> R , F : Send + ' static , R : Sync + Send + ' static , { let ( task , result , status ) = { let result = Arc :: new ( Mutex :: new ( None ) ? ) ; let status = Arc :: new ( Queue :: new ( 1 ) ? ) ; let task_result = result . clone ( ) ; let task_status = status . clone ( ) ; let task = self . start ( move | _this_task | { { let mut lock = task_result . lock ( Duration :: infinite ( ) ) . unwrap ( ) ; let r = func ( ) ; * lock = Some ( r ) ; } // release our reference to the mutex, so it can be deconstructed drop ( task_result ) ; task_status . send ( ComputeTaskStatus :: Finished , Duration :: infinite ( ) ) . unwrap ( ) ; } ) ? ; ( task , result , status ) } ; Ok ( ComputeTask { task : task , result : result , status : status , finished : false , } ) }
Spawn a task that can post a return value to the outside.
Spawn a task that can post a return value to the outside .
&self
func
F
&self
func
F