I think the right approach here is to recognize that you have a more
complex protocol than is currently reflected in your code and dive
into Racket's evt support.
In this particular case, I suggest you make a new channel that the
loop in the thread also listens on, If yet another channel comes in on
that one, you flush all pending messages and then send a message back
saying "I'm done". Then the code that catches the exit can use that
mechanism to communicate "I'm about to exit, please finish up".
On Wed, Jan 31, 2018 at 4:00 PM, Alexander McLin <alex.mc...@gmail.com> wrote:
> So I am using Racket's logging facilities in a command-line tool I'm
> developing. I have various defined loggers in a sensible hierarchical
> configuration for use as needed.
> During the tool's start up period prior to calling the main function I set
> up a log receiver to receive messages at the desired level and place it
> inside a sync loop within its own thread. Each time a sync event is
> received, it is written out to the port, then loop back to waiting for the
> next sync event.
> It works reasonably well except I have a new problem, when the tool exits,
> it often exits before the thread handling the log receiver propagation to
> the port has finished receiving all the log events, as a result my logging
> output is frequently truncated.
> Given this undesired situation, I need to figure out a better way to
> reliably propagate all log messages to ports before the tool exits normally
> or due to a raised exception.
> There is `with-logging-to-port` except I will need to set up multiple ports
> and the idea of wrapping the tool's main body with multiple
> `with-logging-to-port` for each port isn't appealing and it still doesn't
> resolve the problem.
> I was wondering if anyone has a better suggestion? Is there a way to detect
> if there are pending log events waiting to be received by the log receiver?
> I realize the fundamental nature of my issue is that Racket's logging is
> asynchronous while I want synchronous behavior. I may be better off just
> using old-fashioned `println`s
> Thank you for your suggestions.
> Alexander McLin
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
For more options, visit https://groups.google.com/d/optout.