Skip to content

Allow wrapping of all registered callbacks with global wrapper. #128

Open
@creationix

Description

@creationix

This depends on #127.

Once global error-handling is implemented, we will add global event wrapping. Every place where C accepts a lua function to be used as a callback later on, it will be optionally replaced with a new function (usually a wrapped version). This is useful for event tracing, long stack traces and other diagnostics related to event chains and trees.

The global callback wrapper/mutator will be set the same way as the global error handler in #127, but as a third arg to uv.run(mode, onError, onRegister)

The onRegister(type, scope, fn) function will return an optional function to replace the passed in fn. For example, a simple logger that logs all timer setups and timeout will look like:

uv.run(nil, nil, function (type, scope, fn)
  -- Ignore non-timer events
  if type ~= "timer" then return end
  print("setup", scope)
  return function (...)
    print("emit", scope)
    return fn(...)
  end
end)

local timer = uv.new_timer()
timer:start(100, 100, function ()
  print("tick")
end)

This would print setup uv_timer_t: 0x41bc5c60 before timer:start() returned and then later on every interval tick would print emit uv_timer_t: 0x41bc5c60 before running the callback that prints tick.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions