invenia/Memento.jl

Async Handlers

rofinn opened this issue · 3 comments

Rather having loggers asynchronously calling handlers, we should allow handlers to take an async argument during construction which allows it to control how messages are asynchronously emitted.

Some useful notes:

  • Async behavious orginially added here: a42336f
  • As of #99 the loggers don't asynchronously call handlers

If #96 (comment) is true, in particular

We'll still need to be careful in the emit methods that @async is being called after we've formatted the record.

Then I'm not sure it makes sense to have an async option at all, as in most emit functions the only thing that occurs after the formatting is actually calling printstyled or println.

A way this might work is to asynchronously format the record for all its loggers, then asynchronously send the formatted string to their emit message, which will mean

emit(handler::DefaultHandler{F, O}, rec::Record) -> emit(handler::DefaultHandler{F, O}, rec::Record, formatted_str)

Which I'm not sure we want to do?

Then I'm not sure it makes sense to have an async option at all, as in most emit functions the only thing that occurs after the formatting is actually calling printstyled or println

That's exactly where we'd want to use @async because println or generally writing the message may be high latency with low cpu usage. Formatting the message should be relatively CPU intensive, so @async won't get us much there. I suppose one thing we should do is run the println, write, etc in a try/catch to warn about any failure in the task.