Skip to content

Instantly share code, notes, and snippets.

@dmorosinotto
Forked from glennblock/invoker.cs
Created October 29, 2013 15:36
Show Gist options
  • Save dmorosinotto/7216999 to your computer and use it in GitHub Desktop.
Save dmorosinotto/7216999 to your computer and use it in GitHub Desktop.
public Func<IDictionary<string, object>, Task<object>> Invoke(Func<IDictionary<string, object>, object> executor)
{
Func<IDictionary<string, object>, Task<object>> invoker = null;
if (executor.Method.ReturnType != typeof (Task<object>))
{
invoker =
p =>
{
var task = new Task<object>(() => executor(p));
task.Start();
return task;
};
}
else
{
invoker = p => (Task<object>) executor(p);
}
return invoker;
}
var edge = require('edge');
var hello = edge.func('scs', function() {/*
Invoke(d=>d["value"])
*/});
hello({"value": "Hello from scriptcs"}, function(error,result) {
if (error) throw error;
console.log(result.Result);
});
var edge = require('edge');
var hello = edge.func('scs', function() {/*
Func<IDictionary<string,object>, Task<object>> execute = p=> Task.FromResult<object>(p["value"]);
execute
*/});
hello({"value": "Hello from scriptcs"}, function(error,result) {
if (error) throw error;
console.log(result.Result);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment