rehanift/engine.js — pull request #14 by rubymaverick (2012-04-28 21:48:21+00:00)
Title: Call the eval event when a task is called without a console payload.  

Ran into issue #12. When undefined is returned from the `setCode` snippet, the `eval` event never fires, so I'm not sure how one could ever know when the code is "finished" This isn't a problem when using `engine.js` with something like `socket.io` (like in the example app) but it can be a problem when using inside a function that takes a callback which needs to be called to continue processing.

There might be a different approach altogether that could maybe make this cleaner, which is to give two different API's to `engine.js` depending on whether it's used with something like `socket.io` or when used in the callback example. Here is an example of how I'm trying to use inside of a function that expects a callback (assuming my other pull request):

```javascript
var client = require('engine.js').engine.client.create();

var run = function(callback) {
var task = client.createTask();
task.setContext("(function(locals) { return {}})");
task.setLocals({});
task.setCode("1 + 1");

task.on('eval', function(data) {
context.result = data;
});

task.on('output', function(data) {
context.logs.push(data);
});

task.on('end', function() {
callback context
});

task.run();
};
```

I could see an interface like so being offered optionally for this scenario:

```javascript
var run = function(callback) {
var task = client.createTask();
task.setContext("(function(locals) { return {}})");
task.setLocals({});
task.setCode("1 + 1");

task.run(function(err, result, logs){
callback result, logs
});
};
```

What do you think?