Skip to content

godot needs a new API #64

@jcrugzz

Description

@jcrugzz

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: 'user@host.com' })

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 `user@host.com`
// 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: 'user@host.com' }))
  ]
}).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 `user@host.com`
// 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: 'user@host.com' }));
    }
  ]
}).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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions