pub fn with_name(name: Option<String>) -> io::Result<Self> {
		let (stop, stopped) = futures::oneshot();
		let (tx, rx) = mpsc::channel();
		let mut tb = thread::Builder::new();
		if let Some(name) = name {
			tb = tb.name(name);
		}

		let handle = tb.spawn(move || {
			let mut tp_builder = tokio::executor::thread_pool::Builder::new();

			let pool_size = match num_cpus::get_physical() {
				1 => 1,
				2...4 => 2,
				_ => 3,
			};

			tp_builder
				.pool_size(pool_size)
				.name_prefix("jsonrpc-eventloop-");

			let runtime = tokio::runtime::Builder::new()
				.threadpool_builder(tp_builder)
				.build();

			match runtime {
				Ok(mut runtime) => {
					tx.send(Ok(runtime.executor())).expect("Rx is blocking upper thread.");
					let terminate = futures::empty().select(stopped)
						.map(|_| ())
						.map_err(|_| ());
					runtime.spawn(terminate);
					runtime.shutdown_on_idle().wait().unwrap();
				},
				Err(err) => {
					tx.send(Err(err)).expect("Rx is blocking upper thread.");
				}
			}
		}).expect("Couldn't spawn a thread.");

		let exec = rx.recv().expect("tx is transfered to a newly spawned thread.");

		exec.map(|executor| RpcEventLoop {
			executor,
			close: Some(stop),
			handle: Some(handle),
		})
	}
/// Spawns a new named thread with the `EventLoop`.
Spawns a new named thread with the `EventLoop`.
Spawns a new named thread with the ` EventLoop ` .
pub fn with_name(name: Option<String>) -> io::Result<Self> {
		let (stop, stopped) = futures::oneshot();
		let (tx, rx) = mpsc::channel();
		let mut tb = thread::Builder::new();
		if let Some(name) = name {
			tb = tb.name(name);
		}
		let handle = tb.spawn(move || {
			let mut tp_builder = tokio::executor::thread_pool::Builder::new();
			let pool_size = match num_cpus::get_physical() {
				1 => 1,
				2...4 => 2,
				_ => 3,
			};
			tp_builder
				.pool_size(pool_size)
				.name_prefix("jsonrpc-eventloop-");
			let runtime = tokio::runtime::Builder::new()
				.threadpool_builder(tp_builder)
				.build();
			match runtime {
				Ok(mut runtime) => {
					tx.send(Ok(runtime.executor())).expect("Rx is blocking upper thread.");
					let terminate = futures::empty().select(stopped)
						.map(|_| ())
						.map_err(|_| ());
					runtime.spawn(terminate);
					runtime.shutdown_on_idle().wait().unwrap();
				},
				Err(err) => {
					tx.send(Err(err)).expect("Rx is blocking upper thread.");
				}
			}
		}).expect("Couldn't spawn a thread.");
		let exec = rx.recv().expect("tx is transfered to a newly spawned thread.");
		exec.map(|executor| RpcEventLoop {
			executor,
			close: Some(stop),
			handle: Some(handle),
		})
	}
pub fn with_name ( name : Option < String > ) -> io :: Result < Self > { let ( stop , stopped ) = futures :: oneshot ( ) ; let ( tx , rx ) = mpsc :: channel ( ) ; let mut tb = thread :: Builder :: new ( ) ; if let Some ( name ) = name { tb = tb . name ( name ) ; } let handle = tb . spawn ( move | | { let mut tp_builder = tokio :: executor :: thread_pool :: Builder :: new ( ) ; let pool_size = match num_cpus :: get_physical ( ) { 1 => 1 , 2 ... 4 => 2 , _ => 3 , } ; tp_builder . pool_size ( pool_size ) . name_prefix ( " " ) ; let runtime = tokio :: runtime :: Builder :: new ( ) . threadpool_builder ( tp_builder ) . build ( ) ; match runtime { Ok ( mut runtime ) => { tx . send ( Ok ( runtime . executor ( ) ) ) . expect ( " " ) ; let terminate = futures :: empty ( ) . select ( stopped ) . map ( | _ | ( ) ) . map_err ( | _ | ( ) ) ; runtime . spawn ( terminate ) ; runtime . shutdown_on_idle ( ) . wait ( ) . unwrap ( ) ; } , Err ( err ) => { tx . send ( Err ( err ) ) . expect ( " " ) ; } } } ) . expect ( " " ) ; let exec = rx . recv ( ) . expect ( " " ) ; exec . map ( | executor | RpcEventLoop { executor , close : Some ( stop ) , handle : Some ( handle ) , } ) }
Spawns a new named thread with the `EventLoop`.
Spawns a new named thread with the ` EventLoop ` .
name
Option<String>
name
Option<String>