The stupid question is the question not asked | |
PerlMonks |
Sharing a filehandle with an asynchronous eventby stevieb (Canon) |
on Jan 23, 2018 at 15:52 UTC ( [id://1207765]=perlquestion: print w/replies, xml ) | Need Help?? |
stevieb has asked for the wisdom of the Perl Monks concerning the following question: Esteemed Monks and friends... I'm just putting the finishing touches on a rather large and complex project and noticed an issue with my logging mechanism. Trying to simplify things for clarity, I share an object that contains a logging object that holds an internal file handle for writing. I then spin off an async event that runs at every X seconds. This event receives a copy of the object that contains the log object. All parts of the application write to the log file just fine, except for the code that runs within the event. Here is a *very* dumbed down example of what I mean:
What I need is for all $log->_0() entries to go into the specified file, but the log file ends up looking like this, with only the main log entries making it to the file:
The Async::Event::Interval is a distribution that simply runs a specified subroutine every X seconds (in this case, 1). It's exceptionally basic, and I wrote it for a single purpose (well, that, and to learn). In the above case, nothing is passed in, the event simply uses the $log object from within the file scope itself. Is there a way to share a handle like this? If not, can anyone recommend the proper way to do these things (I won't object to using a different async-event type distribution if necessary)? Thanks, -stevieb
Back to
Seekers of Perl Wisdom
|
|