Beispiel #1
0
 internal void For(_Computation <T, object> computation)
 {
     this._HookAction(
         this.entity,
         () => this.describeComputation(computation.ToString()),
         () => this._For(computation)
         );
 }
Beispiel #2
0
        private _Result <R> _For <R>(_Computation <T, R> computation) // TODO: should we accept an interface here? make Lambda an interface? or add Operation interface?
        {
            var timeoutSpan = TimeSpan.FromSeconds(this.timeout);
            var finishTime  = DateTime.Now.Add(timeoutSpan);

            // System.Exception failFastError; // TODO: consider some failfast logic...
            while (true)
            {
                try
                {
                    return(computation._Invoke(this.entity));
                }
                // catch (InvalidCastException error)
                // {
                //     failFastError = error;
                //     break;
                // }
                catch (System.Exception error)
                {
                    if (DateTime.Now > finishTime)
                    {
                        // TODO: should we move this error formatting to the Error class definition?
                        var describedLambda = this.describeComputation(computation.ToString());
                        var failure         = new TimeoutException(
                            "\n"
                            + $"Timed out after {this.timeout}s, while waiting for:\n"
                            + $"\t{this.entity}.{describedLambda}\n" // TODO: handle trailing spaces
                            + "Reason:\n"
                            + $"\t{error.Message}"                   // TODO: error.Message or error?
                            ,
                            error
                            );

                        throw failure;
                    }
                    Thread.Sleep(TimeSpan.FromSeconds(this.polling).Milliseconds);
                }
            }
            // throw failFastError;
        }