Chanquo(pronounce chanko) is the partial implementation of Golang-channel for Unity.
assume that the type like below is exists,
public struct T {}
create typed channel and send T data to the channel.
var ch = Chan<T>.Make();
ch.Send(new T(){});
// start receiving data asynchronously.
ch.Receive(
(T data, bool ok) => {
// ok will become false when the channel is closed somewhere.
// when ok is false, data is empty.
}
);
or
// receive data until Chan<T> is closed.
yield return Channels.For<T>(
T t =>
{
}
);
or
// wait first data then go through.
yield return Channels.WaitFirst<T>();
or
// wait first data then go through and get received data.
var cor = Channels.WaitFirstResult<T>();
yield return cor;
var result = cor.Result;
Close() closes channel. or you can close channel by specify type.
ch.Close();
or
Channels.Close<T>();
when the Chan is closed, WaitFirst(), WaitFirstResult() and For's blocking will end.