Пример #1
0
Файл: IO.cs Проект: sq/Libraries
            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);
                    }
                }
            }
Пример #2
0
Файл: IO.cs Проект: sq/Libraries
        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);
        }
Пример #3
0
Файл: IO.cs Проект: sq/Libraries
            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);
                    }
                }
            }
Пример #4
0
Файл: IO.cs Проект: sq/Libraries
        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);
        }
Пример #5
0
 public override void ExitState()
 {
     pitResponse.Dispose();
 }
Пример #6
0
        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);
            }
        }
Пример #7
0
        public void DisposingFutureInvokesOnDisposeHandlers () {
            bool[] invoked = new bool[1];
            
            var f = new Future<object>();
            f.RegisterOnDispose((_) => {
                invoked[0] = true;
            });

            f.Dispose();
            Assert.IsTrue(invoked[0]);
        }
Пример #8
0
 public void IfCompletedDisposeHasNoEffect () {
     var f = new Future<object>();
     f.Complete(5);
     f.Dispose();
     Assert.AreEqual(5, f.Result);
     Assert.IsFalse(f.Disposed);
 }
Пример #9
0
 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);
 }
Пример #10
0
Файл: IO.cs Проект: sq/Fracture
        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;
        }
Пример #11
0
Файл: IO.cs Проект: sq/Fracture
        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();
 }
Пример #13
0
        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;
        }
Пример #14
0
 public override void Dispose()
 {
     OpenSignal.Set();
     ThunkSignal.Dispose();
     base.Dispose();
 }
Пример #15
0
 public virtual void Dispose()
 {
     Future.Dispose();
     Future  = null;
     Failure = null;
 }