Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Orchestra
JavaScript
Tree: d7efdafbfa

README.markdown

Orchestra

A micro-framework for working with events in javascript.

The question

If i have two or more events, but must take some action to end or wait for a series of events, how to do this gracefully?

Why?

I know of no project supported the idea that i want, which is more connected to events that only by implementing callbacks, which would be the case async, in fact the idea is to "listen" to events around the system when they occur, maybe 2 or more, the system takes care of the action would be a kind of event emitter pumped.

The difference of this approach to async i get free to mix functions, something that does not support async.

Trying

  var orchestraing = new orchestra();

  orchestraing.on('geocode1,geocode2', function(data) {
      console.log(data); //montarota
  });

  fs.readFile('/etc/passwd' , orchestraing.emitter("geocode1"));
  fs.stat('/etc/passwd' , orchestraing.emitter("geocode2"));

My code that made me think about it

  var x1, x2, result1, result2;

  var buildRoute = function() {
      //Run after the first and second stage
      if (x1 && x2) {
          //Build route
      }
  }

  fs.readFile('/etc/passwd', function (err, data) {
      x1 = true;
      result1 = ofAjaxorNet
      buildRoute();
  });

  fs.readFile('/etc/passwd', function (err, data) {
      x2 = true;
      result2 = ofAjaxorNet
      buildRoute();
  });

Examples

  var orchestraing = new orchestra();

  orchestraing.on('geocode1', function(data) {
      assert.isNotNull(data.geocode1);
  });

  orchestraing.on('geocode2', function(data) {
      assert.isNotNull(data.geocode2);
  });

  orchestraing.on('geocode1 geocode2', function(data) {
      assert.isNotNull(data.geocode1);
      assert.isNotNull(data.geocode2);
  });

  fs.readFile('/etc/passwd' , orchestraing.emitter("geocode1"));
  fs.stat('/etc/passwd' , orchestraing.emitter("geocode2"));



  var orchestraing = new orchestra();

  orchestraing.on('geocode1,geocode2', function(data) {
      console.log('oi 1');
  });

  orchestraing.on('geocode1,geocode2', function(data) {
      console.log('oi 2');
  });

  fs.readFile('/etc/passwd' , orchestraing.emitter("geocode1"));
  fs.stat('/etc/passwd' , orchestraing.emitter("geocode2"));


  var orchestraing = new orchestra();

  orchestraing.on('geocode1', function(data) {
      assert.isNotNull(data.geocode1);
  });

  orchestraing.on('geocode2', function(data) {
      assert.isNotNull(data.geocode2);
  });

  orchestraing.on('geocode1,geocode2', function(data) {
      assert.isNotNull(data.geocode1);
      assert.isNotNull(data.geocode2);
  });

  fs.readFile('/etc/passwd', function (err, data) {
      orchestraing.emit("geocode1",data);
  });

  fs.readFile('/etc/passwd', function (err, data) {
      orchestraing.emit("geocode2",data);
  });

Install

npm install orchestra

Credits

History

The first version was born during QconSP 2010 in a chat with Emerson Macedo in the bar after QCon. In the day next, i implemented during the lecture of Ebay and turned a GIST. Since i came thinking of ideas to improve and transform into a interesting framework about events, taking ideas from Luis Cipriani Nando Viera Complex Systems Events, among others, and systems.

Roadmap

  • Allow orchestra a few events, and fallbacks
  • Support functions such as map and reduce
  • Write as a module in C, to perform the best

License

Copyright (c) <2011> Renato Augusto Viço Elias renato.elias@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.