private Guid addCallback(JavaScriptValue value, CancellationTokenSource source) { Guid result = Guid.NewGuid(); ServiceNode.WithContext(() => { value.AddRef();//hold the callback function }); list.Add(result, new Tuple <JavaScriptValue, CancellationTokenSource>(value, source)); return(result); }
private void releaseCallback(Guid id) { if (!list.ContainsKey(id)) { return;//ignore the request if id does not exists } ServiceNode.WithContext(() => { list[id].Item1.Release(); //release the callback function reference }); list[id].Item2.Cancel(); //cancel the interval loop list.Remove(id); }