Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

godot needs a new API #64

Open
jcrugzz opened this issue Dec 31, 2013 · 3 comments
Open

godot needs a new API #64

jcrugzz opened this issue Dec 31, 2013 · 3 comments

Comments

@jcrugzz
Copy link
Member

jcrugzz commented Dec 31, 2013

What has always been my favorite part of godot is its use of streams. Transform, "read-write" or "through" streams are the best mechanism for assessing data on the fly and we use them heavily in godot for all our reactors. Currently we are able to setup a reactor pipe-chain as follows..

var g = require('godot');

var pipeChain = 
  g.reactor()
    .where('service', '*/health/heartbeat')
    .expire(1000 * 60)
    .email({ to: '[email protected]' })

Now even though this provides a simple and clean api, it hides the fact that we are using native node streams and also restricts users to the transform streams that we have available as reactors. We want to expose the raw unifying interface that native streams provide to allow you to have greater control over your event processing!

With this goal in mind, we have a couple api possibilities based on my discussion with @indexzero. Both will allow the use of the native node .pipe() method for creating custom pipe chains, allowing you to use any object based transform stream available in npm!

The other change that you will notice is that we will expose all of the native godot reactor streams on the godot object itself.

var g = require('godot');

//
// Reactor server which will email `[email protected]`
// whenever any service matching /.*\/health\/heartbeat/
// fails to check in after 60 seconds.
//
g.createServer({
  //
  // Defaults to UDP
  //
  type: 'udp',
  reactors: [
    g.where('service', '*/health/heartbeat')
     .pipe(g.expire(1000 * 60))
     .pipe(g.email({ to: '[email protected]' }))
  ]
}).listen(1337);

So the first api is the most ideal IMO. All you need to do is pass your own custom pipe chain(s) into the reactors array and voila!

The other API is as follows..

var g = require('godot');

//
// Reactor server which will email `[email protected]`
// whenever any service matching /.*\/health\/heartbeat/
// fails to check in after 60 seconds.
//
g.createServer({
  //
  // Defaults to UDP
  //
  type: 'udp',
  reactors: [
    function health(socket) {
      socket.
       .pipe(g.where('service', '*/health/heartbeat'))
       .pipe(g.expire(1000 * 60))
       .pipe(g.email({ to: '[email protected]' }));
    }
  ]
}).listen(1337);

Now even though I like the first API better, It may not be possible to preserve the multiplexing functionality of godot where you are able to create a separate stream for each incoming connection. This API should ensure this is possible.

Now this is just the beginning of the road to godot v1.0. Please post any questions or concerns if you have any!

@mmalecki
Copy link
Contributor

@jcrugzz I like the idea of passing a factory as a reactor. We won't be able to preserve mutliplexing functionality otherwise.

@indexzero
Copy link
Member

+1 for sure to this. Thanks for opening an issue with the code from our discussion.

@indexzero
Copy link
Member

@jcrugzz @mmalecki Check this out. Similar approach, but built on streams2 transforms. https://github.com/Obvious/sculpt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants