Skip to content

Instantly share code, notes, and snippets.

@rightfold
Last active August 29, 2015 14:00
Show Gist options
  • Save rightfold/11324960 to your computer and use it in GitHub Desktop.
Save rightfold/11324960 to your computer and use it in GitHub Desktop.
namespace ErSharp {
public sealed class Sender<T> {
private BlockingCollection<T> Queue;
internal Sender(BlockingCollection<T> queue) {
Queue = queue;
}
public void Send(T value) {
queue.Add(value);
}
}
public static class ErSharp {
public static Sender<T> Spawn<T>(Action<Func<T>> action) {
var queue = new BlockingCollection<T>(ConcurrentQueue<T>());
var thread = new Thread(() => {
action(queue.Take);
});
thread.Start();
return new Sender<T>(queue);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment