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()
Undocumented in source.

Members

Functions

close
void close()
Undocumented in source. Be warned that the author may not have intended to support it.
runAsync
void runAsync(Dg dg)
Undocumented in source. Be warned that the author may not have intended to support it.
runWait
void runWait(Dg dg)
Undocumented in source. Be warned that the author may not have intended to support it.

Inherited Members

From TcpConnection

doSend
sizediff_t doSend(void[] buffer)
Undocumented in source. Be warned that the author may not have intended to support it.
doReceive
sizediff_t doReceive(void[] buffer)
Undocumented in source. Be warned that the author may not have intended to support it.
tryNextAddress
void tryNextAddress()
Undocumented in source. Be warned that the author may not have intended to support it.
onError
void onError(string reason)

Called when an error occurs on the socket.

connect
void connect(string host, ushort port)

Start establishing a connection.

Examples

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

Meta