c3d.thread
the thread module is used for multitasking and sharing data across "channels" IMPORTANT: you can use the threaderror callback for handling errors
new_thread(...) | creates a new thread object |
---|---|
new_channel() | creates a new channel object without a set name |
get_channel(name) | returns a channel object for a given name. |
thread | the thread object |
channel | the channel object. |
- new_thread(...)Source
creates a new thread object
Parameters
- code string the code to create the thread from in a string form
Or
- path string the path to the file to load the code into the thread from
- new_channel()Source
creates a new channel object without a set name
Returns
- channel the finished channel object
- get_channel(name)Source
returns a channel object for a given name. makes one if it doesnt exist.
Parameters
- name string the name of the channel
Returns
- channel the channel object
- threadSource
the thread object
get_error() if the thread happened to error this returns the error message is_running() checks if the thread is currently running start() starts the execution of this thread wait() waits until the thread finishes execution - get_error()Source
if the thread happened to error this returns the error message
Returns
- any msg thread error message
- is_running()Source
checks if the thread is currently running
Returns
- boolean true if thread is running
- start()Source
starts the execution of this thread
- wait()Source
waits until the thread finishes execution
- channelSource
the channel object. a channel is basically a queue which you can add stuff into to share across your program, the values in the queue also get ids asigned
clear() completely clears the data queue of the channel demand(timeout) returns a value from the queue. get_count() returns the amount of things stored in the queue has_read(ID) checks if a specific value in the queue has been read already peek() reads a value from the queue without removing it pop() removes a value from the queue and returns it push(value) adds a value to the queue of the channel supply(value, timeout) adds a value to the queue of the channel and waits for that value to be read (pop'ed) or for the timeout to go off - clear()Source
completely clears the data queue of the channel
- demand(timeout)Source
returns a value from the queue. if there isnt one it waits for one or for a timeout to happen
Parameters
- timeout number the maximum time to wait for data in the queue
Returns
- any the data removed from the queue
- get_count()Source
returns the amount of things stored in the queue
Returns
- number number of things in the queue
- has_read(ID)Source
checks if a specific value in the queue has been read already
Parameters
- ID string the queue ID of the value
Returns
- boolean whether the value has been read yet
- peek()Source
reads a value from the queue without removing it
Returns
- any data read from the queue
- pop()Source
removes a value from the queue and returns it
Returns
- any data remove from the queue
- push(value)Source
adds a value to the queue of the channel
Parameters
- value any the value to store in the queue
Returns
- string the ID of this value in the queue
- supply(value, timeout)Source
adds a value to the queue of the channel and waits for that value to be read (pop'ed) or for the timeout to go off
Parameters
- value any the value to store in the queue
- timeout number the timeout to set for this supply
Returns
- boolean whether the timeout has gone off