@Def("(is Channel) receive()")
@Doc("Reads a value from the channel. If the channe's buffer is empty,\n" +
"then this blocks until another thread sends a value to it.")
public static class Receive implements Intrinsic {
public Obj invoke(Context context, Obj left, Obj right) {
Channel channel = (Channel) left.getValue();
try {
return channel.receive();
} catch (InterruptedException e) {
// TODO(bob): Better error.
throw context.error("Error", "Interrupted");
}
}