Skip to content

Instantly share code, notes, and snippets.

@clojj
clojj / chan.d
Last active August 29, 2015 14:07 — forked from rjmcguire/chan.d
import core.sync.mutex : Mutex;
import core.thread : Thread, Fiber;
/**
* chan allows messaging between threads without having to deal with locks, similar to how chan works in golang
*/
shared
class chan(T) {
Mutex lock;
private bool closed_; bool closed() {synchronized (lock) {return closed_;}} void Close() { synchronized(lock) { closed_ = true; } }