Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local event = require("event")
- local PORT = 80
- local SEND_ATTEMPTS = 5
- local BACKOFF_BASE = 1 --seconds
- local gdp = {}
- --init
- math.randomseed(os.time())
- --end-init
- local function set_timer(callback, max_wait_time, elapsed_attempts)
- local function on_timer()
- if elapsed_attempts > SEND_ATTEMPTS then --TODO: Check off-by-1 error
- io.write("ERROR: TODO")
- return
- end
- callback()
- set_timer(callback, max_wait_time * 2, elapsed_attempts + 1)
- end
- io.write(elapsed_attempts, ":", event.timer(math.random() * max_wait_time, on_timer, 1), "\n")
- end
- local function backoff(callback)
- set_timer(callback, BACKOFF_BASE, 1)
- end
- function gdp.send(to, ...)
- local args = table.pack(...)
- local send_actual = function()
- io.write("id:", args[1], " ")
- end
- backoff(send_actual)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement