change concurrency library to use new catch usage
parent
6b4227b022
commit
cd32714099
|
@ -128,12 +128,12 @@ M: crash-command run-rpc-command ( command -- shutdown? result )
|
||||||
: (robust-rpc-server) ( worker -- )
|
: (robust-rpc-server) ( worker -- )
|
||||||
[
|
[
|
||||||
receive over send
|
receive over send
|
||||||
] [
|
]
|
||||||
|
catch
|
||||||
[
|
[
|
||||||
"Worker died, Starting a new worker" print
|
"Worker died, Starting a new worker" print
|
||||||
drop [ handle-rpc-message ] spawn-linked-server
|
drop [ handle-rpc-message ] spawn-linked-server
|
||||||
] when
|
] when
|
||||||
] catch
|
|
||||||
(robust-rpc-server) ;
|
(robust-rpc-server) ;
|
||||||
|
|
||||||
: robust-rpc-server ( -- process )
|
: robust-rpc-server ( -- process )
|
||||||
|
|
|
@ -164,8 +164,7 @@ USING: kernel concurrency concurrency-examples threads vectors
|
||||||
] spawn-link drop
|
] spawn-link drop
|
||||||
receive
|
receive
|
||||||
]
|
]
|
||||||
[
|
catch
|
||||||
] catch
|
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ 50 ] [
|
[ 50 ] [
|
||||||
|
|
|
@ -209,7 +209,7 @@ TUPLE: linked-exception error ;
|
||||||
#! Same as spawn but if the quotation throws an error that
|
#! Same as spawn but if the quotation throws an error that
|
||||||
#! is uncaught, that error gets propogated to the process
|
#! is uncaught, that error gets propogated to the process
|
||||||
#! performing the spawn-link.
|
#! performing the spawn-link.
|
||||||
[ [ [ rethrow-linked ] when* ] catch ] cons
|
[ catch [ rethrow-linked ] when* ] cons
|
||||||
[ in-thread ] self make-linked-process [ with-process ] over slip ;
|
[ in-thread ] self make-linked-process [ with-process ] over slip ;
|
||||||
|
|
||||||
#! A common operation is to send a message to a process containing
|
#! A common operation is to send a message to a process containing
|
||||||
|
|
|
@ -349,9 +349,9 @@ can catch it:</p>
|
||||||
"This will not print" print
|
"This will not print" print
|
||||||
] spawn-link drop
|
] spawn-link drop
|
||||||
receive
|
receive
|
||||||
] [
|
]
|
||||||
[ "Exception caught." print ] when
|
catch [ "Exception caught." print ] when
|
||||||
] catch</span>
|
</span>
|
||||||
=> "Exception caught."
|
=> "Exception caught."
|
||||||
</pre>
|
</pre>
|
||||||
<p>Exceptions are only raised in the parent when the parent does a
|
<p>Exceptions are only raised in the parent when the parent does a
|
||||||
|
@ -427,12 +427,12 @@ worker:</p>
|
||||||
[
|
[
|
||||||
#! Forward all messages to worker
|
#! Forward all messages to worker
|
||||||
receive over send
|
receive over send
|
||||||
] [
|
]
|
||||||
|
catch
|
||||||
[
|
[
|
||||||
"Worker died, Starting a new worker" print
|
"Worker died, Starting a new worker" print
|
||||||
drop [ handle-rpc-message ] spawn-linked-server
|
drop [ handle-rpc-message ] spawn-linked-server
|
||||||
] when
|
] when
|
||||||
] catch
|
|
||||||
(robust-rpc-server) ;
|
(robust-rpc-server) ;
|
||||||
|
|
||||||
: robust-rpc-server ( -- process )
|
: robust-rpc-server ( -- process )
|
||||||
|
|
Loading…
Reference in New Issue