andrewvc / dripdrop

Experimental Swiss Army Knife of Network Concurrency, ZeroMQ, EventMachine, WebSockets, HTTP, and More
MIT License
144 stars 10 forks source link

Nodelet interfaces #17

Closed andrewvc closed 9 years ago

andrewvc commented 13 years ago

I'm unhappy with nodelet class interface as it stands now, I'm thinking of ways to fix it. Here's some ideas, I'd like some feedback.

As it stands now, you declare your nodelet class, and can optionally include a #configure method, which gets called on initialization. This interacts awkwardly when combined with Node#nodelet do; #block stuff; end. Proposed new interface:

class MyNodelet < DripDrop::Node::Nodelet def pre_action end def action end def post_action end end

given this new system, when you call say nodelet :mynodelet, MyNLetClass {|nlet| ... }

what would happen is:

  1. The nodelet gets initialized
  2. Your block gets run in the context of the nodelet
  3. pre_action gets called
  4. action gets called.
  5. post_action gets called.

All of the pre/post/action methods would be optional.

This all dovetails with the new Node#run_list setting quite well, as having a standard #action method means you don't manually have to kick-off your nodelets later.