multithreading - Safe fire and forget method in Perl -
i need execute method (not process) asynchronously in perl code, must ensure code never raise exception , stop main task execution.
what best way call method asynchronously , silencing potential exception whether called method internal exception whether threading exception?
in java had this:
// task runs here try { // assyncrounous method invocation (fire , forget) new mythread().start(); } catch (throwable e) { // silent error } // task continues here
you have 2 options if want execute arbitrary code asynchronously: can run in separate process, or can run in separate thread. using separate process make more robust, use thread.
use threads; $thread = async { code() };
join
thread wait finish.
Comments
Post a Comment