@@ -491,6 +491,9 @@ public async Task<List<WinGetPackage>> GetInstalledPackagesAsync(string packageI
491491 /// <param name="packageId">
492492 /// The id or name of the package for the search.
493493 /// </param>
494+ /// <param name="cancellationToken">
495+ /// The <see cref="System.Threading.CancellationToken"/> for the <see cref="System.Threading.Tasks.Task"/>.
496+ /// </param>
494497 /// <returns>
495498 /// A <see cref="WGetNET.WinGetPackage"/> instances or <see langword="null"/> if no match was found.
496499 /// </returns>
@@ -503,11 +506,17 @@ public async Task<List<WinGetPackage>> GetInstalledPackagesAsync(string packageI
503506 /// <exception cref="System.ArgumentNullException">
504507 /// A provided argument is null.
505508 /// </exception>
506- public async Task < WinGetPackage ? > GetExactInstalledPackageAsync ( string packageId )
509+ public async Task < WinGetPackage ? > GetExactInstalledPackageAsync ( string packageId , CancellationToken cancellationToken = default )
507510 {
508511 ArgsHelper . ThrowIfStringIsNullOrWhiteSpace ( packageId , "packageId" ) ;
509- //TODO: Add cancellation token
510- ProcessResult result = await ExecuteAsync ( WinGetArguments . List ( ) . AcceptSourceAgreements ( ) ) ;
512+
513+ ProcessResult result = await ExecuteAsync ( WinGetArguments . List ( ) . AcceptSourceAgreements ( ) , false , cancellationToken ) ;
514+
515+ // Return null if the task was cancled
516+ if ( cancellationToken . IsCancellationRequested )
517+ {
518+ return null ;
519+ }
511520
512521 return PackageHelper . MatchExact (
513522 ProcessOutputReader . ToPackageList ( result . Output , PackageAction . InstalledList ) ,
@@ -527,6 +536,9 @@ public async Task<List<WinGetPackage>> GetInstalledPackagesAsync(string packageI
527536 /// <param name="sourceName">
528537 /// The name of the source for the search.
529538 /// </param>
539+ /// <param name="cancellationToken">
540+ /// The <see cref="System.Threading.CancellationToken"/> for the <see cref="System.Threading.Tasks.Task"/>.
541+ /// </param>
530542 /// <returns>
531543 /// A <see cref="WGetNET.WinGetPackage"/> instances or <see langword="null"/> if no match was found.
532544 /// </returns>
@@ -539,14 +551,21 @@ public async Task<List<WinGetPackage>> GetInstalledPackagesAsync(string packageI
539551 /// <exception cref="System.ArgumentNullException">
540552 /// A provided argument is null.
541553 /// </exception>
542- public async Task < WinGetPackage ? > GetExactInstalledPackageAsync ( string packageId , string sourceName )
554+ public async Task < WinGetPackage ? > GetExactInstalledPackageAsync ( string packageId , string sourceName , CancellationToken cancellationToken = default )
543555 {
544556 ArgsHelper . ThrowIfStringIsNullOrWhiteSpace ( packageId , "packageId" ) ;
545557 ArgsHelper . ThrowIfStringIsNullOrWhiteSpace ( sourceName , "sourceName" ) ;
546- //TODO: Add cancellation token
558+
547559 ProcessResult result =
548560 await ExecuteAsync (
549- WinGetArguments . List ( ) . Query ( packageId ) . Source ( sourceName ) . AcceptSourceAgreements ( ) ) ;
561+ WinGetArguments . List ( ) . Query ( packageId ) . Source ( sourceName ) . AcceptSourceAgreements ( ) ,
562+ false , cancellationToken ) ;
563+
564+ // Return null if the task was cancled
565+ if ( cancellationToken . IsCancellationRequested )
566+ {
567+ return null ;
568+ }
550569
551570 return PackageHelper . MatchExact (
552571 ProcessOutputReader . ToPackageList ( result . Output , PackageAction . InstalledList ) ,
0 commit comments