Skip to main content

events

Description

Listen for various events in Porla, such as torrents being added, moved, finished, etc.

Events

These are the events supported. The name is the string you pass as the first argument to on, and the argument is what you get back in your callback parameters.

NameArguments
torrent_addedTorrentHandle
torrent_finishedTorrentHandle
torrent_movedTorrentHandle
torrent_pausedTorrentHandle
torrent_removedInfoHash
torrent_resumedTorrentHandle

Exports

Function on(string, callback)

Registers an event handler for an event. When the event triggers, the callback is invoked with the event args.

The function returns a SignalConnection that can be used to disconnect the event handler at any time. Once disconnected, you need to register the event again to trigger your callback.

local events = require("events")

local sc = events.on("torrent_added", function(torrent)
-- torrent is a TorrentHandle
local status = torrent:status()
print(status.name)
end)

-- sc is a SignalConnection
-- disconnect the event handler immediately - the callback
-- will never be invoked.
sc:disconnect()

Types

SignalConnection

The SignalConnection represents a connection to a specific event handler.

Function disconnect()

Disconnects the event handler. The callback will not be invoked again.