Sandbox: Lua: Thread - ov-studio/Vital.sandbox GitHub Wiki

━ What's the Objective?

Most importantly for Async operation when you've plenty of executions to be performed on some heavy data which would cause infinite loop termination normally. Essentially its also needed by Async/Await functionality provided by the same module.

━ APIs

━ thread:getType() (Shared)

@Objective: Retrieve's instance's type.
local string: type = self:getType()

━ thread:create() (Shared)

@Objective: Creates a new thread.
--Syntax #1:
local thread: cThread = thread:create(
  function: exec
)

--Syntax #2:
local thread: cThread = async(
  function: exec
)

━ thread:createHeartbeat() (Shared)

@Objective: Creates a new heartbeat.
local thread: cThread = thread:createHeartbeat(
  function: conditionExec,
  function: exec,
  int = rate
)

━ thread:destroy() (Shared)

@Objective: Destroys an existing thread.
local bool: result = self:destroy()

━ thread:pause() (Shared)

@Objective: Pauses the current thread.
local bool: result = thread:pause()

━ thread:status() (Shared)

@Objective: Retrieves the status of a specified thread.
local string: status = self:status()

━ thread:resume() (Shared)

@Objective: Resumes a paused thread.
--Syntax #1:
local bool: result = self:resume()

--Syntax #2:
--Note: Use this when you need to repeatedly resume a thread
local bool: result = self:resume(
  table: {
    int: executions = 1 --Number of executions within a resume
    int: frames = 100 --Number of frames to run the resume interval at
  }
)

━ thread:sleep() (Shared)

@Objective: Pauses the current thread for specified duration.
--Duration must in milliseconds
local bool: result = self:sleep(
  int: duration
)

━ thread:await() (Shared)

@Objective: Pauses the current thread & awaits the exec to be resolved.
local bool: result = self:await(
  function: exec
)

━ thread:resolve() (Shared)

@Objective: Explicitly resolves an awaiting thread.
local bool: result = self:resolve(
  ~: ...arguments
)