@@ -54,10 +54,6 @@ public event EventHandler<EventArgs> NotFoundEvent
5454
5555 private EventHandler < EventArgs > ? _notFound ;
5656
57- private readonly List < Func < NotFoundContext , ValueTask > > _notFoundHandlers = new ( ) ;
58-
59- private CancellationTokenSource ? _notFoundCts ;
60-
6157 // For the baseUri it's worth storing as a System.Uri so we can do operations
6258 // on that type. System.Uri gives us access to the original string anyway.
6359 private Uri ? _baseUri ;
@@ -487,126 +483,6 @@ protected async ValueTask<bool> NotifyLocationChangingAsync(string uri, string?
487483 }
488484 }
489485
490- /// <summary>
491- /// Notifies the registered handlers of the current ot found event.
492- /// </summary>
493- /// <returns>A <see cref="ValueTask{TResult}"/> representing the completion of the operation. If the result is <see langword="true"/>, the navigation should continue.</returns>
494- protected async ValueTask < bool > NotifyNotFoundAsync ( )
495- {
496- _notFoundCts ? . Cancel ( ) ;
497- _notFoundCts = null ;
498-
499- var handlerCount = _notFoundHandlers . Count ;
500-
501- if ( handlerCount == 0 )
502- {
503- return true ;
504- }
505-
506- var cts = new CancellationTokenSource ( ) ;
507-
508- _notFoundCts = cts ;
509-
510- var cancellationToken = cts . Token ;
511- var context = new NotFoundContext
512- {
513- CancellationToken = cancellationToken ,
514- } ;
515-
516- try
517- {
518- if ( handlerCount == 1 )
519- {
520- var handlerTask = InvokeNotFoundHandlerAsync ( _notFoundHandlers [ 0 ] , context ) ;
521-
522- if ( handlerTask . IsFaulted )
523- {
524- await handlerTask ;
525- return false ; // Unreachable because the previous line will throw.
526- }
527-
528- if ( context . DidPreventRendering )
529- {
530- return false ;
531- }
532-
533- if ( ! handlerTask . IsCompletedSuccessfully )
534- {
535- await handlerTask . AsTask ( ) . WaitAsync ( cancellationToken ) ;
536- }
537- }
538- else
539- {
540- var notFoundHandlersCopy = ArrayPool < Func < NotFoundContext , ValueTask > > . Shared . Rent ( handlerCount ) ;
541-
542- try
543- {
544- _notFoundHandlers . CopyTo ( notFoundHandlersCopy ) ;
545-
546- var notFoundTasks = new HashSet < Task > ( ) ;
547-
548- for ( var i = 0 ; i < handlerCount ; i ++ )
549- {
550- var handlerTask = InvokeNotFoundHandlerAsync ( notFoundHandlersCopy [ i ] , context ) ;
551-
552- if ( handlerTask . IsFaulted )
553- {
554- await handlerTask ;
555- return false ; // Unreachable because the previous line will throw.
556- }
557-
558- if ( context . DidPreventRendering )
559- {
560- return false ;
561- }
562-
563- notFoundTasks . Add ( handlerTask . AsTask ( ) ) ;
564- }
565-
566- while ( notFoundTasks . Count != 0 )
567- {
568- var completedHandlerTask = await Task . WhenAny ( notFoundTasks ) . WaitAsync ( cancellationToken ) ;
569-
570- if ( completedHandlerTask . IsFaulted )
571- {
572- await completedHandlerTask ;
573- return false ; // Unreachable because the previous line will throw.
574- }
575-
576- notFoundTasks . Remove ( completedHandlerTask ) ;
577- }
578- }
579- finally
580- {
581- ArrayPool < Func < NotFoundContext , ValueTask > > . Shared . Return ( notFoundHandlersCopy ) ;
582- }
583- }
584-
585- return ! context . DidPreventRendering ;
586- }
587- catch ( TaskCanceledException ex )
588- {
589- if ( ex . CancellationToken == cancellationToken )
590- {
591- // This navigation was in progress when a successive navigation occurred.
592- // We treat this as a canceled navigation.
593- return false ;
594- }
595-
596- throw ;
597- }
598- finally
599- {
600- cts . Cancel ( ) ;
601- cts . Dispose ( ) ;
602-
603- if ( _notFoundCts == cts )
604- {
605- _notFoundCts = null ;
606- }
607- }
608- }
609-
610486 private async ValueTask InvokeLocationChangingHandlerAsync ( Func < LocationChangingContext , ValueTask > handler , LocationChangingContext context )
611487 {
612488 try
@@ -623,22 +499,6 @@ private async ValueTask InvokeLocationChangingHandlerAsync(Func<LocationChanging
623499 }
624500 }
625501
626- private async ValueTask InvokeNotFoundHandlerAsync ( Func < NotFoundContext , ValueTask > handler , NotFoundContext context )
627- {
628- try
629- {
630- await handler ( context ) ;
631- }
632- catch ( OperationCanceledException )
633- {
634- // Ignore exceptions caused by cancellations.
635- }
636- catch ( Exception ex )
637- {
638- HandleNotFoundHandlerException ( ex , context ) ;
639- }
640- }
641-
642502 /// <summary>
643503 /// Handles exceptions thrown in location changing handlers.
644504 /// </summary>
@@ -647,14 +507,6 @@ private async ValueTask InvokeNotFoundHandlerAsync(Func<NotFoundContext, ValueTa
647507 protected virtual void HandleLocationChangingHandlerException ( Exception ex , LocationChangingContext context )
648508 => throw new InvalidOperationException ( $ "To support navigation locks, { GetType ( ) . Name } must override { nameof ( HandleLocationChangingHandlerException ) } ") ;
649509
650- /// <summary>
651- /// Handles exceptions thrown in NotFound rendering handlers.
652- /// </summary>
653- /// <param name="ex">The exception to handle.</param>
654- /// <param name="context">The context passed to the handler.</param>
655- protected virtual void HandleNotFoundHandlerException ( Exception ex , NotFoundContext context )
656- => throw new InvalidOperationException ( $ "To support not found rendering locks, { GetType ( ) . Name } must override { nameof ( HandleNotFoundHandlerException ) } ") ;
657-
658510 /// <summary>
659511 /// Sets whether navigation is currently locked. If it is, then implementations should not update <see cref="Uri"/> and call
660512 /// <see cref="NotifyLocationChanged(bool)"/> until they have first confirmed the navigation by calling
0 commit comments