示例#1
0
 /// <summary>
 /// Wait until the provided <paramref name="statePredicate"/> action returns true,
 /// or the <paramref name="timeout"/> is reached (default is one second).
 ///
 /// The <paramref name="statePredicate"/> is evaluated initially, and then each time
 /// the <paramref name="renderedFragment"/> renders.
 /// </summary>
 /// <param name="renderedFragment">The render fragment or component to attempt to verify state against.</param>
 /// <param name="statePredicate">The predicate to invoke after each render, which must returns <c>true</c> when the desired state has been reached.</param>
 /// <param name="timeout">The maximum time to wait for the desired state.</param>
 /// <exception cref="WaitForFailedException">Thrown if the <paramref name="statePredicate"/> throw an exception during invocation, or if the timeout has been reached. See the inner exception for details.</exception>
 public static void WaitForState(this IRenderedFragmentBase renderedFragment, Func <bool> statePredicate, TimeSpan?timeout = null)
 {
     using var waiter = new WaitForStateHelper(renderedFragment, statePredicate, timeout);
     try
     {
         waiter.WaitTask.Wait();
     }
     catch (AggregateException e)
     {
         throw e.InnerException;
     }
 }
示例#2
0
        private async Task <IRenderedComponent <KaTeX> > WaitForKatexToHaveRendered(KaTeX cut, int cutId, TimeSpan?timeout = default)
        {
            var icut = cut.ToIRenderedComponent(cutId, this.Services);

            using var waiter = new WaitForStateHelper(icut, predicate, WaitForStateTimeout);
            await waiter.WaitTask;             // don't just return the task because then the waiter is disposed of too early

            return(icut !);

            bool predicate()
            {
                return(cut.markup != null);
            }
        }