Package com.stuffwithstuff.magpie.interpreter

Examples of com.stuffwithstuff.magpie.interpreter.Channel


  }
 
  @Def("(== Channel) new()")
  public static class NewChannel implements Intrinsic {
    public Obj invoke(Context context, Obj left, Obj right) {
      Channel channel = new Channel();
      return context.instantiate(sChannelClass, channel);
    }
View Full Code Here


  @Def("(== Channel) new(capacity is Int)")
  public static class NewChannel_Capacity implements Intrinsic {
    public Obj invoke(Context context, Obj left, Obj right) {
      int capacity = right.asInt();
     
      Channel channel = new Channel(capacity);
      return context.instantiate(sChannelClass, channel);
    }
View Full Code Here

  @Def("(is Channel) send(value)")
  @Doc("Sends the given value to the channel. The value must be\n" +
       "thread-safe. If the channel's buffer is full, this blocks")
  public static class Send implements Intrinsic {
    public Obj invoke(Context context, Obj left, Obj right) {
      Channel channel = (Channel) left.getValue();
     
      try {
        channel.send(right);
        return context.nothing();
      } catch (InterruptedException e) {
        // TODO(bob): Better error.
        throw context.error("Error", "Interrupted");
      }
View Full Code Here

  @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");
      }
    }
View Full Code Here

TOP

Related Classes of com.stuffwithstuff.magpie.interpreter.Channel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.