MCPcopy Create free account
hub / github.com/ceifa/wasmoon / setTimeout

Method setTimeout

src/thread.ts:322–340  ·  view source on GitHub ↗
(timeout: number | undefined)

Source from the content-addressed store, hash-verified

320
321 // Set to > 0 to enable, otherwise disable.
322 public setTimeout(timeout: number | undefined): void {
323 if (timeout && timeout > 0) {
324 if (!this.hookFunctionPointer) {
325 this.hookFunctionPointer = this.lua.module.addFunction((): void => {
326 if (Date.now() > timeout) {
327 this.pushValue(new LuaTimeoutError(`thread timeout exceeded`))
328 this.lua.lua_error(this.address)
329 }
330 }, 'vii')
331 }
332
333 this.lua.lua_sethook(this.address, this.hookFunctionPointer, LuaEventMasks.Count, INSTRUCTION_HOOK_COUNT)
334 this.timeout = timeout
335 } else if (this.hookFunctionPointer) {
336 this.hookFunctionPointer = undefined
337 this.timeout = undefined
338 this.lua.lua_sethook(this.address, null, 0, 0)
339 }
340 }
341
342 public getTimeout(): number | undefined {
343 return this.timeout

Callers 2

runMethod · 0.95
jsFuncMethod · 0.80

Calls 1

pushValueMethod · 0.95

Tested by

no test coverage detected