cleanup

PBX Cleanup object.

Functions

Name Summary
list_callbacks

Return a list of names for registered callbacks.

register

Register a function to be called on Summit Application exit.

unregister

Unregister a callback function.

Functions : cleanup

list_callbacks()

Return a list of names for registered callbacks. If you are unsure which callbacks are currently registered, this function will return a list of all the names which are in use. Note that this will not return any information on private callbacks.

Returns
Type Summary

table

Table of string names of callbacks

Usage
local cleanup = require("summit.cleanup")
...
local fn = function() print('hello world') end
cleanup.register(fn, "my_func")
cleanup.register(fn, "other_func")
...
for k,v in pairs(cleanup.list_callbacks) do print(k,v) end
-- prints:
-- 1       "my_func"
-- 2       "other_func"

register(func, name, private)

Register a function to be called on Summit Application exit. Pass a function to this method, and it will be called when the Summit Application finishes, either by channel.hangup or a user hanging up on their end. Note that only one callback can exist for a given name; if you register multiple callbacks to the same name, only the last will be called.

Additionally, you cannot override private callbacks: this will return nil if you try to register a private callback for a name that is already in use.

You may have one private and one non-private callback with the same name without any issue.

Parameters
Name Type Default Summary

func

function

Function to be called

name

string

nil

String name for this callback function (optional; using a name allows you to easily unregister a function if the callback is no longer needed)

private

boolean

false

Bool which determines if this callback is visible in cleanup.list_callbacks or not. Private callbacks also cannot be unregistered.

Returns
Type Summary

string

String name of the callback (either the specified value, or a random UUID if no name was given) or nil if this was an attempt to register a private callback for a name that is already in use.

Usage
local cleanup = require("summit.cleanup")
...
-- calling a function which has no arguments is easy
function do_something()
    local result = http.get("http://www.google.com")
    -- do something with the result
end
cleanup.register(do_something, "do_something")
...
-- calling a function which takes arguments just takes one intermediate step
function do_more(some_arg, another_arg)
    -- function does things with args, etc.
end
local fn = function() do_more("first_value", "second_value") end
cleanup.register(fn, "do_more")

unregister(name)

Unregister a callback function. If you no longer want some registered callback to execute when the Application exists, you can unregister it. Note that you can only unregister non-private callbacks; trying to unregister a private callback will fail.

Parameters
Name Type Default Summary

name

string

String name of the function to remove.

Returns
Type Summary

boolean

Boolean indicating if a callback was removed: true if so, false if no callback by that name was found.

Usage
local cleanup = require("summit.cleanup")
local fn = function() print('hello world') end
cleanup.register(fn, "my_func")
...
cleanup.unregister("my_func") -- returns True