Files
kumomta/docs/reference/events/shutdown_logging.md
T
Wez Furlong 6a05a65f73 mpsc: provide shutdown event and clarify single-consumer parts
It was possible to deadlock your policy by triggering queue
length/emptiness checks conurrently with the queue consumer thread.

Let's make it more explicitly clear which methods cannot be used that
way by making their mutex acquisition non-blocking and raise an error.

In addition, let's improve the close method so that it doesn't require
exclusive access to the consumer side of the queue.

Provide a shutdown_logging event that can be used to explicitly close
queues on shutdown, if that is appropriate for your use case.
2025-07-29 15:22:51 +01:00

796 B

shutdown_logging

kumo.on('shutdown_logging', function() end)

{{since('dev')}}

Called by kumod as part of shutdown, just prior to shutting down all loggers.

The intended use case is for you to be able to close any mpsc queues that you might have defined in your policy, which in turn allows for a more graceful shutdown:

local kumo = require 'kumo'

kumo.on('init', function()
  kumo.spawn_task {
    event_name = 'logger',
    args = {},
  }
end)

kumo.on('logger', function(args)
  local q = kumo.mpsc.define 'queue'
  while true do
    local batch = q:recv_many(100)
    if not batch then
      print 'logger loop done; shutting down'
      return
    end
  end
end)

kumo.on('shutdown_logging', function()
  local q = kumo.mpsc.define 'queue'
  q:close()
end)