void _OnDecodeComplete(IFuture f) { if (Parent.IsDisposed) { Result.Dispose(); return; } var e = f.Error; if (e != null) { Buffer.Dispose(); Result.Fail(e); } else { int numChars = (int)f.Result; if (numChars > 0) { ProcessDecodedChars(); } else { string resultString = Buffer.DisposeAndGetContents(); if (resultString.Length == 0) { resultString = null; } Result.Complete(resultString); } } }
private Future <int> DecodeMoreData() { var f = new Future <int>(); var readData = ReadMoreData(); readData.RegisterOnComplete((_) => { if (IsDisposed) { f.Dispose(); return; } var error = _.Error; if (error != null) { f.Fail(error); return; } var bytesRead = (int)_.Result; try { DecodeBuffer(bytesRead); f.Complete(_DecodedCharacterCount); } catch (FutureHandlerException) { throw; } catch (Exception ex) { f.Fail(ex); } }); return(f); }
private void _OnDecodeComplete(IFuture f) { if (Parent.IsDisposed) { Result.Dispose(); return; } var e = f.Error; if (e != null) { Result.Fail(e); } else { int numChars = (int)f.Result; if (numChars > 0) { ProcessDecodedChars(); } else { Result.Complete(Position - InitialPosition); } } }
public Future <char> Read(bool advance = true) { var f = new Future <char>(); SetPendingOperation(f); char result; if (!GetCurrentCharacter(out result)) { var decodeMoreChars = DecodeMoreData(); decodeMoreChars.RegisterOnComplete((_) => { if (IsDisposed) { f.Dispose(); return; } var error = _.Error; if (error != null) { ClearPendingOperation(f); f.Fail(error); } else { char ch; if (GetCurrentCharacter(out ch)) { if (advance) { ReadNextCharacter(); } ClearPendingOperation(f); f.Complete(ch); } else { ClearPendingOperation(f); f.Complete(null); } } }); } else { if (advance) { ReadNextCharacter(); } ClearPendingOperation(f); f.Complete(result); } return(f); }
public override void ExitState() { pitResponse.Dispose(); }
public void FutureWrapsExceptionIfOnDisposeHandlerThrows () { var f = new Future<object>(); f.RegisterOnDispose((_) => { throw new Exception("pancakes"); }); try { f.Dispose(); Assert.Fail("Exception was swallowed"); } catch (FutureHandlerException fhe) { Assert.IsInstanceOfType(typeof(Exception), fhe.InnerException); Assert.AreEqual("pancakes", fhe.InnerException.Message); } }
public void DisposingFutureInvokesOnDisposeHandlers () { bool[] invoked = new bool[1]; var f = new Future<object>(); f.RegisterOnDispose((_) => { invoked[0] = true; }); f.Dispose(); Assert.IsTrue(invoked[0]); }
public void IfCompletedDisposeHasNoEffect () { var f = new Future<object>(); f.Complete(5); f.Dispose(); Assert.AreEqual(5, f.Result); Assert.IsFalse(f.Disposed); }
public void CannotBeCompletedIfDisposedFirst () { var f = new Future<object>(); f.Dispose(); Assert.IsTrue(f.Disposed); f.Complete(5); Assert.IsTrue(f.Disposed); Assert.IsFalse(f.Completed); }
private Future<int> DecodeMoreData() { var f = new Future<int>(); var readData = ReadMoreData(); readData.RegisterOnComplete((_) => { if (IsDisposed) { f.Dispose(); return; } var error = _.Error; if (error != null) { f.Fail(error); return; } var bytesRead = (int)_.Result; try { DecodeBuffer(bytesRead); f.Complete(_DecodedCharacterCount); } catch (FutureHandlerException) { throw; } catch (Exception ex) { f.Fail(ex); } }); return f; }
public Future<char> Read(bool advance = true) { var f = new Future<char>(); SetPendingOperation(f); char result; if (!GetCurrentCharacter(out result)) { var decodeMoreChars = DecodeMoreData(); decodeMoreChars.RegisterOnComplete((_) => { if (IsDisposed) { f.Dispose(); return; } var error = _.Error; if (error != null) { ClearPendingOperation(f); f.Fail(error); } else { char ch; if (GetCurrentCharacter(out ch)) { if (advance) ReadNextCharacter(); ClearPendingOperation(f); f.Complete(ch); } else { ClearPendingOperation(f); f.Complete(null); } } }); } else { if (advance) ReadNextCharacter(); ClearPendingOperation(f); f.Complete(result); } return f; }
public override void ExitState() { loginTokensResponse.Dispose(); }
private Future<int> DecodeMoreData() { var f = new Future<int>(); var readData = ReadMoreData(); readData.RegisterOnComplete((_) => { if (IsDisposed) { f.Dispose(); return; } var error = _.Error; if (error != null) { f.Fail(error); return; } int bytesRead = (int)(_.Result); try { _DecodedCharacterOffset = 0; _DecodedCharacterCount = 0; _DecodedCharacterCount = _Decoder.GetChars(_InputBuffer, 0, bytesRead, _DecodedBuffer, 0); f.Complete(_DecodedCharacterCount); } catch (FutureHandlerException) { throw; } catch (Exception ex) { f.Fail(ex); } }); return f; }
public override void Dispose() { OpenSignal.Set(); ThunkSignal.Dispose(); base.Dispose(); }
public virtual void Dispose() { Future.Dispose(); Future = null; Failure = null; }