Last active
August 29, 2015 14:00
-
-
Save no-longer-on-githu-b/11324960 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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