pecan

Getting started

Here is an example of pecan usage. For a more in-depth look into each of the annotated features, see the following chapters.

var factory = pecan.Co.co({   // (1)
  var greeted = 0;
  trace("Greeter online!");
  suspend();                  // (2)
  while (true) {              // (3)
    var name = accept();      // (4)
    if (name == null)
      break;
    trace('Hello, $name!');
    yield(++greeted);         // (5)
  }
  trace("Bye!");
}, (_ : String), (_ : Int));  // (6)

var instance = factory.run(); // (7)
                              // output: Greeter online!
instance.wakeup();            // (8)
instance.give("world");       // (9)
                              // output: Hello, world!
instance.take() == 1;         // (10)
instance.give("Haxe");        // output: Hello, Haxe!
instance.take() == 2;
instance.give(null);          // output: Bye!
instance.state == Terminated; // (11)

There are several things to note in the example:

« Previous: Installation Next: Features »