public static PValue RunStatically(StackContext sctx, PValue[] args) { if (sctx == null) throw new ArgumentNullException("sctx"); if (args == null || args.Length == 0 || args[0] == null) return PType.Null.CreatePValue(); var iargs = Call.FlattenArguments(sctx, args, 1); var retChan = new Channel(); var T = new Thread(() => { PValue result; try { result = args[0].IndirectCall(sctx, iargs.ToArray()); } catch (Exception ex) { result = sctx.CreateNativePValue(ex); } retChan.Send(result); }) { IsBackground = true }; T.Start(); return PType.Object.CreatePValue(retChan); }
public static Channel RunAsync(StackContext sctx, Func<PValue> comp) { var retChan = new Channel(); var T = new Thread(() => retChan.Send(comp())) { IsBackground = true }; T.Start(); return retChan; }
private static void _split(IEnumerable<KeyValuePair<Channel, PValue>> cases, out Channel[] channels, out PValue[] handlers) { var chanCases = cases.Where(kvp => kvp.Key != null).ToArray(); var count = chanCases.Length; channels = new Channel[count]; handlers = new PValue[count]; for (var i = 0; i < chanCases.Length; i++) { channels[i] = chanCases[i].Key; handlers[i] = chanCases[i].Value; } }