You need to declare that id, then use it. Like this (using the native timer, same principle using my timer extension):
local id = nil
id = timer.delay(0.1, true, function()
if length == metrics.char_count then
timer.cancel(id)
end
end)