@@ -75,16 +75,16 @@ impl Dispatch for Dispatcher {
7575/// Holds the handle for the subprocess as well as the handle for the socket
7676/// to said subprocess.
7777pub struct LocalDispatcher {
78- runtime : Runtime ,
7978 socket : BackendSocket ,
8079 subprocess : BackendSubprocess ,
80+ runtime : Runtime ,
8181}
8282
8383impl LocalDispatcher {
8484 pub fn create (
8585 resource_path : & Path ,
8686 launch_command : & Vec < String > ,
87- ) -> Result < Self , DispatcherError > {
87+ ) -> DispatcherResult < Self > {
8888 let runtime = match tokio:: runtime:: Builder :: new_current_thread ( )
8989 . enable_all ( )
9090 . build ( ) {
@@ -107,9 +107,9 @@ impl LocalDispatcher {
107107
108108 Ok (
109109 Self {
110- runtime,
111110 socket,
112- subprocess
111+ subprocess,
112+ runtime,
113113 }
114114 )
115115 }
@@ -147,25 +147,16 @@ impl Dispatch for LocalDispatcher {
147147 }
148148}
149149
150- impl Drop for LocalDispatcher {
151- fn drop ( & mut self ) {
152- match self . subprocess . terminate ( ) {
153- Ok ( _) => { } ,
154- Err ( _) => error ! ( "Terminating subprocess returned an error." )
155- } ;
156- }
157- }
158-
159150/// Dispatcher for dispatching FMI commands to a remote backend.
160151///
161152/// Holds the socket to the remote backend.
162153pub struct RemoteDispatcher {
163- runtime : Runtime ,
164154 socket : BackendSocket ,
155+ runtime : Runtime ,
165156}
166157
167158impl RemoteDispatcher {
168- pub fn create ( ) -> Result < Self , DispatcherError > {
159+ pub fn create ( ) -> DispatcherResult < Self > {
169160 let runtime = match tokio:: runtime:: Builder :: new_current_thread ( )
170161 . enable_all ( )
171162 . build ( ) {
@@ -192,8 +183,8 @@ impl RemoteDispatcher {
192183
193184 Ok (
194185 Self {
195- runtime,
196186 socket,
187+ runtime,
197188 }
198189 )
199190 }
@@ -273,7 +264,7 @@ struct BackendSocket {
273264}
274265
275266impl BackendSocket {
276- pub async fn create ( endpoint : & str ) -> Result < Self , DispatcherError > {
267+ pub async fn create ( endpoint : & str ) -> DispatcherResult < Self > {
277268 let mut socket = RepSocket :: new ( ) ;
278269
279270 let endpoint = match socket. bind ( endpoint) . await {
@@ -297,7 +288,7 @@ impl BackendSocket {
297288 /// ZeroMQ message queue, NOT when the message has actually been received
298289 /// by the backend. As such, there is no absolute guarantee that the
299290 /// message has been received when this returns.
300- async fn send < S : Message > ( & mut self , msg : & S ) -> Result < ( ) , DispatcherError > {
291+ async fn send < S : Message > ( & mut self , msg : & S ) -> DispatcherResult < ( ) > {
301292 let bytes_send: Bytes = msg. encode_to_vec ( ) . into ( ) ;
302293 match self . socket . send ( bytes_send. into ( ) ) . await {
303294 Ok ( _) => Ok ( ( ) ) ,
@@ -317,7 +308,7 @@ impl BackendSocket {
317308 ///
318309 /// A call to recv() will await until a message is received through the
319310 /// ZeroMQ socket.
320- async fn recv < R : Message + Default > ( & mut self ) -> Result < R , DispatcherError > {
311+ async fn recv < R : Message + Default > ( & mut self ) -> DispatcherResult < R > {
321312 match self . socket . recv ( ) . await {
322313 Ok ( buf) => {
323314 let buf: Bytes = match buf. get ( 0 ) {
@@ -347,7 +338,7 @@ impl BackendSocket {
347338 async fn send_and_recv < S : Message , R : Message + Default > (
348339 & mut self ,
349340 msg : & S ,
350- ) -> Result < R , DispatcherError > {
341+ ) -> DispatcherResult < R > {
351342 self . send ( msg) . await ?;
352343 self . recv ( ) . await
353344 }
@@ -443,17 +434,4 @@ impl BackendSubprocess {
443434 }
444435 }
445436 }
446-
447- /// Terminates the subprocess
448- ///
449- /// On Unix-like systems, this sends the `SIGTERM` signal to the
450- /// subprocess, which can be caught by the subprocess in order to perform
451- /// cleanup befoure exiting.
452- ///
453- /// On Windows, it invokes `TerminateProcess` on the process handle, which
454- /// cannot be caught.
455- fn terminate ( & mut self ) -> DispatcherResult < ( ) > {
456- self . subprocess . terminate ( )
457- . map_err ( |_| DispatcherError :: SubprocessError )
458- }
459437}
0 commit comments