Hi,
In older haxe I was able to use Threads like:
class MyThread extends sys.thread.Thread { …
Now Its abstract class, how can I do this in haxe 4,x,x?
Hi,
In older haxe I was able to use Threads like:
class MyThread extends sys.thread.Thread { …
Now Its abstract class, how can I do this in haxe 4,x,x?
class MyThread {
final thread:Thread;
public function new(t:Thread) this.thread = thread;
//...
}
or
abstract MyThread(Thread) from Thread {
//....
}
Ok, I tried:
class MyThread {
final thread: sys.thread.Thread;
public function new(t: sys.thread.Thread) this.thread = thread;
//…
}
and I have error “Assigning a value to itself” for this code: this.thread = thread;
I need to make not abstract class, can’t use ```
abstract MyThread(Thread) from Thread {
//…
}
Oh, found issue
class ThreadBase {
final thread: sys.thread.Thread;
public function new(t: sys.thread.Thread) this.thread = t;
//…
}
Thanks! It works now
Only problem
var a: MyThread = new MyThread(null);
trace(a.current());//error
Its not actually extended class, current method not available. I have compile time error
I have to re declare all methods
Maybe you can use MainLoop.addThread() to do same thing as MyThread
I need Thread as class not abstract. In haxe you can’t make/extend class from abstract, which is looking strange to me. To make it work I have to re declare abstract methods in my class:
class MyThread {
final thread: sys.thread.Thread;
public function new(t: sys.thread.Thread) this.thread = t;
public function sendMessage(msg:Dynamic):Void {
thread.sendMessage(msg);
}
public static function current():MyThread {
return new MyThread(sys.thread.Thread.current());
}
public static function create(callb:Void->Void):MyThread {
return newMyThread(sys.thread.Thread.create(callb));
}
public static function readMessage(block:Bool):Dynamic {
return sys.thread.Thread.readMessage(block);
}
@:op(A == B)
public function equals(other:MyThread):Bool {
return thread.equals(other.thread);
}
}
© 2018-2020 Haxe Foundation - Powered by Discourse