This function isn't part of the nodeMCU code, nor the Expressif SDK. It is part of the xtensa-lx106 boot ROM and looking at a disassembly of this ROM entry, what this function does is to do a low level machine code loop which will delay the specified number of μSec with interrupts disabled. As the nodeMCU documentation states (translating Chinese English in to English):
tmr.delay() will make the CPU work in non-interrupt mode, so other instructions and interrupts will be blocked. Take care in using this function.
Q: why does it disable interrupts? A: because if they are enabled then there is no guarantee that the delay will be as requested.
Q: when does it make sense to use a tmr.delay()? A: when you want to have exact timing control on an external hardware I/O (e.g. lifting a GPIO pin high for 20 μSec)
Q: when does it make sense not to use a tmr.delay()? A: pretty much every other circumstance. A good indication is if the delay if for more than a few mSec, then the programmer is doing something wrong, and at best the tmr.delay() will be having no functional purpose; at worst it will break the code. (The ESP kernel is non-preemptive, so a lot of things don't actually get scheduled until the Lua execution is idle and waiting for an event to happen.)
So don't use it. nodeMCU is event driven so find the correct even an use it. This could be a timer.alarm() or even another event, such as an sk:on("sent", sendMore) where sendMore() might be:
function sendMore(sk)
local recs = toBeSent it a global rather than an upvalue !!
if type(recs) = 'array' and #recs>0 then
sk:send(recs[1])
toBeSent = {unpack(recs, 2)} -- shift the array to pop the sent record
else
sk:close()
end
end