-
Notifications
You must be signed in to change notification settings - Fork 4
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
Feature: ability to persist context's between task runs #15
Comments
It sounds like the goal is to be able to read back the context's globals after a task has run. Here is a sketch of how I can see this working with the existing API. Would this work for your use-case? // File: counting_context.js /////////////////////////////////////////
(function(locals) {
return {
count: 3,
hello: "world",
incr_global: function(){
this.count+=1;
return this.count;
}
,incr_local: function(){
locals.count++;
return locals.count;
}
};
});
//////////////////////////////////////////////////////////////////////
var engine = require("engine.js").engine,
client = engine.client.create(),
task = client.createTask(),
fs = require("fs");
task.setContext(fs.readFileSync("./counting_context.js","utf-8"));
task.setCode("incr_global() + incr_local();");
task.setLocals({count:5, foo:"bar"});
task.on("eval", function(last_eval, globals, locals){
/*
* last_eval: The last evaluated expression from the context
* ie. 10
*
* globals: An object-literal of all global variables
* (except functions) from the context, after the
* task has finished
* ie. {
* count: 4,
* hello: "world"
* }
*
* locals: An object-literal of all local variables from the
* task-run, after the task has finished
* ie. {
* count: 6,
* foo: "bar"
* }
*
*/
});
task.run(); |
This would help a lot actually, and is probably much easier to implement than my suggestion. To move forward, should I just write up some pending specs, and document the feature? |
Ok. In preparation for this I started integrated contexify as the actual code execution strategy (rather than using the native If you could write a end-to-end test for this that would be a great way to get started. |
Awesome, that looks pretty handy! I'll hopefully get some time tonight to write that end to end spec. |
…and globals back on 'eval' event) issue rehanift#15
…and globals back on 'eval' event) issue rehanift#15
For the use case I am trying to use
engine.js
for It would be very helpful to be able to setup a context and then have multiple tasks run against that context. The use case (for me) is this:A user submits code that somehow changes the context (let's say, incrementing a counter), does a console.log, and returns a certain value. I want to be able to verify three things:
Currently, I can only verify the first two in the above list. I think to give the most flexibility and to limit the changes to the scope and feature set of
engine.js
, we could allow multiple tasks to run against a single context. The api might look something like this (assuming the api changes discussed in pull request 14:Please let me know if this even sounds doable.
The text was updated successfully, but these errors were encountered: