Skip to content

Instantly share code, notes, and snippets.

@pcibraro
Created September 22, 2014 15:22
Show Gist options
  • Save pcibraro/1dadbf99eff02df7ed90 to your computer and use it in GitHub Desktop.
Save pcibraro/1dadbf99eff02df7ed90 to your computer and use it in GitHub Desktop.
class Program
{
static void Main(string[] args)
{
using (Isolated<Work> isolated = new Isolated<Work>())
{
isolated.Value.CallEdge();
}
}
}
public class Work : MarshalByRefObject
{
public void CallEdge()
{
var msg = "Hello world";
var t = CallEdgeAsync(msg);
t.Wait();
}
public async Task<IDictionary<string, object>> CallEdgeAsync(string msg)
{
var load = Edge.Func(@"
return function (msg, callback) {
callback(null, { prop : 'foo' });
}
");
var rawresult = await load(msg);
return (IDictionary<string, object>)rawresult;
}
}
public sealed class Isolated<T> : IDisposable where T : MarshalByRefObject
{
private AppDomain _domain;
private T _value;
public Isolated()
{
_domain = AppDomain.CreateDomain("Isolated:" + Guid.NewGuid(),
null, AppDomain.CurrentDomain.SetupInformation);
Type type = typeof(T);
_value = (T)_domain.CreateInstanceAndUnwrap(type.Assembly.FullName, type.FullName);
}
public T Value
{
get
{
return _value;
}
}
public void Dispose()
{
if (_domain != null)
{
AppDomain.Unload(_domain);
_domain = null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment