pub fn new(
        mut schedulers: Vec<Box<dyn Scheduler + Send>>,
        sub_scheduler_handler: &mut SubSchedulerHandler,
    ) -> Result<MultiScheduler, SchedulerError> {
        let (core_tx, core_rx) = mpsc::channel();

        for (i, scheduler) in schedulers.iter_mut().enumerate() {
            // All sub-schedulers will callback to the MultiScheduler; these callbacks will
            // record the index of the calling sub-scheduler
            let tx = core_tx.clone();
            scheduler
                .set_result_callback(Box::new(move |result| {
                    tx.send(core::MultiSchedulerCoreMessage::BatchResult(i, result))
                        .unwrap_or_else(|err| {
                            error!(
                                "scheduler {} failed to send result to MultiScheduler: {}",
                                i, err
                            )
                        });
                }))
                .map_err(|err| {
                    SchedulerError::Internal(format!(
                        "failed to set result callback for sub-scheduler {}: {}",
                        i, err
                    ))
                })?;
            let tx = core_tx.clone();
            scheduler
                .set_error_callback(Box::new(move |err| {
                    tx.send(core::MultiSchedulerCoreMessage::SubSchedulerError(i, err))
                        .unwrap_or_else(|err| {
                            error!(
                                "scheduler {} failed to send error to MultiScheduler: {}",
                                i, err
                            )
                        });
                }))
                .map_err(|err| {
                    SchedulerError::Internal(format!(
                        "failed to set error callback for sub-scheduler {}: {}",
                        i, err
                    ))
                })?;
            // Each sub-scheduler except for the first is sent to the SubSchedulerHandler to run in
            // parallel; the first sub-scheduler's task iterator and notifier will be returned by
            // the multi-scheduler's take_task_iterator and new_notifier methods.
            if i > 0 {
                sub_scheduler_handler
                    .pass_scheduler(
                        scheduler.take_task_iterator().map_err(|err| {
                            SchedulerError::Internal(format!(
                                "failed to take task iterator from sub-scheudler {}: {}",
                                i, err
                            ))
                        })?,
                        scheduler.new_notifier().map_err(|err| {
                            SchedulerError::Internal(format!(
                                "failed to get new notifier from sub-scheduler {}: {}",
                                i, err
                            ))
                        })?,
                    )
                    .map_err(|err| {
                        SchedulerError::Internal(format!(
                            "failed to pass sub-scheduler {} to handler: {}",
                            i, err,
                        ))
                    })?;
            }
        }

        let shared_lock = Arc::new(Mutex::new(shared::MultiSchedulerShared::new(schedulers)));

        let core_handle = core::MultiSchedulerCore::new(shared_lock.clone(), core_rx).start()?;

        Ok(MultiScheduler {
            shared_lock,
            core_handle: Some(core_handle),
            core_tx,
        })
    }
/// Returns a newly created `MultiScheduler` that runs the specified sub-schedulers.
Returns a newly created `MultiScheduler` that runs the specified sub-schedulers.
Returns a newly created ` MultiScheduler ` that runs the specified sub - schedulers .
pub fn new(
        mut schedulers: Vec<Box<dyn Scheduler + Send>>,
        sub_scheduler_handler: &mut SubSchedulerHandler,
    ) -> Result<MultiScheduler, SchedulerError> {
        let (core_tx, core_rx) = mpsc::channel();
        for (i, scheduler) in schedulers.iter_mut().enumerate() {
            // All sub-schedulers will callback to the MultiScheduler; these callbacks will
            // record the index of the calling sub-scheduler
            let tx = core_tx.clone();
            scheduler
                .set_result_callback(Box::new(move |result| {
                    tx.send(core::MultiSchedulerCoreMessage::BatchResult(i, result))
                        .unwrap_or_else(|err| {
                            error!(
                                "scheduler {} failed to send result to MultiScheduler: {}",
                                i, err
                            )
                        });
                }))
                .map_err(|err| {
                    SchedulerError::Internal(format!(
                        "failed to set result callback for sub-scheduler {}: {}",
                        i, err
                    ))
                })?;
            let tx = core_tx.clone();
            scheduler
                .set_error_callback(Box::new(move |err| {
                    tx.send(core::MultiSchedulerCoreMessage::SubSchedulerError(i, err))
                        .unwrap_or_else(|err| {
                            error!(
                                "scheduler {} failed to send error to MultiScheduler: {}",
                                i, err
                            )
                        });
                }))
                .map_err(|err| {
                    SchedulerError::Internal(format!(
                        "failed to set error callback for sub-scheduler {}: {}",
                        i, err
                    ))
                })?;
            // Each sub-scheduler except for the first is sent to the SubSchedulerHandler to run in
            // parallel; the first sub-scheduler's task iterator and notifier will be returned by
            // the multi-scheduler's take_task_iterator and new_notifier methods.
            if i > 0 {
                sub_scheduler_handler
                    .pass_scheduler(
                        scheduler.take_task_iterator().map_err(|err| {
                            SchedulerError::Internal(format!(
                                "failed to take task iterator from sub-scheudler {}: {}",
                                i, err
                            ))
                        })?,
                        scheduler.new_notifier().map_err(|err| {
                            SchedulerError::Internal(format!(
                                "failed to get new notifier from sub-scheduler {}: {}",
                                i, err
                            ))
                        })?,
                    )
                    .map_err(|err| {
                        SchedulerError::Internal(format!(
                            "failed to pass sub-scheduler {} to handler: {}",
                            i, err,
                        ))
                    })?;
            }
        }
        let shared_lock = Arc::new(Mutex::new(shared::MultiSchedulerShared::new(schedulers)));
        let core_handle = core::MultiSchedulerCore::new(shared_lock.clone(), core_rx).start()?;
        Ok(MultiScheduler {
            shared_lock,
            core_handle: Some(core_handle),
            core_tx,
        })
    }
pub fn new ( mut schedulers : Vec < Box < dyn Scheduler + Send > > , sub_scheduler_handler : & mut SubSchedulerHandler , ) -> Result < MultiScheduler , SchedulerError > { let ( core_tx , core_rx ) = mpsc :: channel ( ) ; for ( i , scheduler ) in schedulers . iter_mut ( ) . enumerate ( ) { // All sub-schedulers will callback to the MultiScheduler; these callbacks will // record the index of the calling sub-scheduler let tx = core_tx . clone ( ) ; scheduler . set_result_callback ( Box :: new ( move | result | { tx . send ( core :: MultiSchedulerCoreMessage :: BatchResult ( i , result ) ) . unwrap_or_else ( | err | { error ! ( " " i err ) } ) ; } ) ) . map_err ( | err | { SchedulerError :: Internal ( format ! ( " " i err ) ) } ) ? ; let tx = core_tx . clone ( ) ; scheduler . set_error_callback ( Box :: new ( move | err | { tx . send ( core :: MultiSchedulerCoreMessage :: SubSchedulerError ( i , err ) ) . unwrap_or_else ( | err | { error ! ( " " i err ) } ) ; } ) ) . map_err ( | err | { SchedulerError :: Internal ( format ! ( " " i err ) ) } ) ? ; // Each sub-scheduler except for the first is sent to the SubSchedulerHandler to run in // parallel; the first sub-scheduler's task iterator and notifier will be returned by // the multi-scheduler's take_task_iterator and new_notifier methods. if i > 0 { sub_scheduler_handler . pass_scheduler ( scheduler . take_task_iterator ( ) . map_err ( | err | { SchedulerError :: Internal ( format ! ( " " i err ) ) } ) ? , scheduler . new_notifier ( ) . map_err ( | err | { SchedulerError :: Internal ( format ! ( " " i err ) ) } ) ? , ) . map_err ( | err | { SchedulerError :: Internal ( format ! ( " " i err ) ) } ) ? ; } } let shared_lock = Arc :: new ( Mutex :: new ( shared :: MultiSchedulerShared :: new ( schedulers ) ) ) ; let core_handle = core :: MultiSchedulerCore :: new ( shared_lock . clone ( ) , core_rx ) . start ( ) ? ; Ok ( MultiScheduler { shared_lock , core_handle : Some ( core_handle ) , core_tx , } ) }
Returns a newly created `MultiScheduler` that runs the specified sub-schedulers.
Returns a newly created ` MultiScheduler ` that runs the specified sub - schedulers .
schedulers
Vec<Box<dyn Scheduler + Send>>
sub_scheduler_handler
&mut SubSchedulerHandler
schedulers
Vec<Box<dyn Scheduler + Send>>
sub_scheduler_handler
&mut SubSchedulerHandler