ThreadAnchor

An object which allows calling a function in a different thread. Create ThreadAnchor in the main thread (the thread in which the code will run in), and then call runWait or runAsync from a different thread.

The main thread must be running an unblocked ae.net.asockets event loop.

Constructors

this
this(Flag!"daemon" daemon)

Constructor.

Members

Functions

close
void close()

Close the connection to the main thread.

runAsync
void runAsync(Dg dg)

Run the specified delegate in the origin thread, without waiting for it to finish.

runWait
void runWait(Dg dg)

Run the specified delegate in the origin thread, and wait for it to finish.

Inherited Members

From TcpConnection

connect
alias connect = SocketConnection.connect
connect
void connect(string host, ushort port)

Start establishing a connection.

Examples

void onConnect(TcpConnection socket)
{
	auto mainThread = thisThread;
	new Thread({
		string s = readln();
		mainThread.runAsync({
			socket.send(s);
			socket.disconnect();
		});
	}).start();
}

Meta