new TCThread(name, func, onErroropt)
One‑shot task executed on the shared cached thread pool. Supports cooperative
pause/resume/stop and exposes liveness/interruption flags for predictable coordination.
Examples
// Example: basic usage
var t = new TCThread("job1", () => delay(100));
t.start();
print(TCWait(t, 1000));
// Example: cooperative pause/resume
var t2 = new TCThread("pausable", (self) => {
for (var i=0;i<3;i++){
delay(60);
if (self.isPaused()) while (self.isPaused()) delay(40);
}
});
t2.start(t2);
t2.pause();
delay(150);
t2.resume();
print(TCWait(t2, 1000));
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
name |
string | Logical name used in registries and for TCWait by name. |
|
func |
function | User function executed when the thread starts. Arguments passed to |
|
onError |
function |
<optional> |
Optional non‑fatal error handler. |
Methods
getFunctionName() → {string}
Example
var t=new TCThread("p",()=>delay(500));
t.start();
print(t.getFunctionName());
Returns:
Logical name.
- Type
- string
getJavaThread() → {java.lang.Thread|null}
Example
var t=new TCThread("p",()=>delay(500));
t.start();
var jt=t.getJavaThread();
Returns:
Underlying Java thread.
- Type
- Thread | null
isAlive() → {boolean}
Check liveness (includes short "starting" window).
Example
var t=new TCThread("p",()=>delay(500));
t.start();
print(t.isAlive());
Returns:
- Type
- boolean
isPaused() → {boolean}
Example
var t=new TCThread("p",()=>delay(500));
t.start();
print(t.isPaused());
Returns:
Whether the thread is paused.
- Type
- boolean
isRunning() → {boolean}
Example
var t=new TCThread("p",()=>delay(500));
t.start();
print(t.isRunning());
Returns:
Whether the thread is still running.
- Type
- boolean
isVirtual() → {false}
Example
var t=new TCThread("p",()=>delay(500));
t.start();
print(t.isVirtual()); // false
Returns:
Distinguish from virtual threads.
- Type
- false
join()
Blocking join; prefer TCWait with timeout.
Example
var t=new TCThread("p",()=>delay(500));
t.start();
t.join();
pause()
Request cooperative pause.
Example
var t=new TCThread("p",()=>delay(500));
t.start();
t.pause();
resume()
Resume after a cooperative pause.
Example
var t=new TCThread("p",()=>delay(500));
t.start();
t.resume();
start()
Start execution exactly once. Additional calls are ignored.
Arguments are forwarded to the user function.
Example
// Example: start twice (second call is ignored)
var t = new TCThread("once", () => delay(10));
t.start();
stop()
Signal the thread to stop and attempt to interrupt/cancel underlying Java thread.
Example
// Example: stop a long task early
var t = new TCThread("willStop", () => delay(2000));
t.start();
delay(100);
t.stop();
print(TCWait(t, 300)); // usually false
wasInterrupted() → {boolean}
Example
var t=new TCThread("p",()=>delay(500));
t.start();
print(t.wasInterrupted());
Returns:
True if interrupted path observed.
- Type
- boolean