/// <summary>
 /// Disposes the <paramref name="dbSet"/> after enumeration.
 /// </summary>
 /// <typeparam name="T">The element type.</typeparam>
 /// <param name="source">The source.</param>
 /// <param name="dbSet">The database set.</param>
 /// <returns></returns>
 public static IAsyncEnumerable <T> DisposeAfterEnumeration <T>(this IAsyncEnumerable <T> source, IAsyncDisposable dbSet)
 => new AutoDisposingAsyncEnumerable <T>(source, dbSet);
Beispiel #2
0
 public static async void TestAsyncUsing(IAsyncDisposable disposable)
 {
     await using (disposable) {
         Console.WriteLine("Hello");
     }
 }
Beispiel #3
0
 private static void Use(IAsyncDisposable test)
 {
     throw new NotImplementedException();
 }
 /// <inheritdoc />
 void IAsyncDisposablesBag.AddDisposable(IAsyncDisposable disposable)
 {
     _disposables.Push(disposable);
 }
Beispiel #5
0
 private void Use(IAsyncDisposable asyncDisposable)
 {
 }
Beispiel #6
0
 public FirstTestedClass(IAsyncDisposable testDependency, int a, string s, SecondTestedClass st)
 {
 }
Beispiel #7
0
 public void AddCompletedAsyncDisposable(IAsyncDisposable asyncDisposable)
 => (CompletedAsyncDisposables ??= new List <IAsyncDisposable>()).Add(asyncDisposable);
        public static StableCompositeAsyncDisposable Create(IAsyncDisposable disposable1, IAsyncDisposable disposable2)
        {
            if (disposable1 == null)
            {
                throw new ArgumentNullException(nameof(disposable1));
            }
            if (disposable2 == null)
            {
                throw new ArgumentNullException(nameof(disposable2));
            }

            return(new Binary(disposable1, disposable2));
        }
 public Binary(IAsyncDisposable disposable1, IAsyncDisposable disposable2)
 {
     _disposable1 = disposable1;
     _disposable2 = disposable2;
 }
 public AsyncDisposable2(IAsyncDisposable a, IDisposable b)
 {
     _a = a;
     _b = b;
 }
 public ActorCompleteLifeCycleInterceptor(IAbortableTaskQueue iqueue, IAsyncDisposable iAsyncDisposable)
 {
     _Queue            = iqueue;
     _IAsyncDisposable = iAsyncDisposable;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AutoDisposingAsyncEnumerable{T}"/> class.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="dbSet">The database set.</param>
 /// <exception cref="ArgumentNullException">
 /// source
 /// or
 /// dbSet
 /// </exception>
 public AutoDisposingAsyncEnumerable(IAsyncEnumerable <T> source, IAsyncDisposable dbSet)
 {
     _source          = source ?? throw new ArgumentNullException(nameof(source));
     _asyncDisposable = dbSet ?? throw new ArgumentNullException(nameof(dbSet));
 }
Beispiel #13
0
 /// <summary>Configures how awaits on the tasks returned from an async disposable will be performed.</summary>
 /// <param name="source">The source async disposable.</param>
 /// <param name="continueOnCapturedContext">Whether to capture and marshal back to the current context.</param>
 /// <returns>The configured async disposable.</returns>
 public static ConfiguredAsyncDisposable ConfigureAwait(
     this IAsyncDisposable source,
     Boolean continueOnCapturedContext)
 {
     return(new ConfiguredAsyncDisposable(source, continueOnCapturedContext));
 }
Beispiel #14
0
 internal void Dispose(IAsyncDisposable d)
 {
     d.DisposeAsync()
     .AsTask()
     .ContinueWith(DisposeHandleAction, this);
 }
 public void Complete(IAsyncDisposable result)
 {
     mPendingRequest.Complete(result);
 }
 /// <summary>
 /// Safely disposes an <see cref="IAsyncDisposable"/> object.
 /// </summary>
 /// <param name="disposable">Object to dispose (can be <see langword="null"/>).</param>
 public static ValueTask DisposeSafelyAsync(this IAsyncDisposable disposable) =>
 disposable?.DisposeAsync() ?? default;
        public Task DisposeAsync()
        {
            IAsyncDisposable asyncDisposable = Connection;

            return(asyncDisposable.DisposeAsync());
        }
 public static ConfiguredAsyncDisposable AnyContext(this IAsyncDisposable source)
 {
     return(source.ConfigureAwait(continueOnCapturedContext: false));
 }
Beispiel #19
0
 public Disposable(IAsyncDisposable disposable) => _disposable = disposable;
 internal ConfiguredAsyncDisposable(IAsyncDisposable source, bool continueOnCapturedContext)
 {
     _source = source;
     _continueOnCapturedContext = continueOnCapturedContext;
 }
Beispiel #21
0
        public async Task StopAsync()
        {
            if (_logger.IsInfo)
            {
                _logger.Info("Shutting down...");
            }
            _context.RunnerCancellation?.Cancel();

            if (_logger.IsInfo)
            {
                _logger.Info("Stopping session monitor...");
            }
            _context.SessionMonitor?.Stop();

            if (_logger.IsInfo)
            {
                _logger.Info("Stopping discovery app...");
            }
            Task discoveryStopTask = _context.DiscoveryApp?.StopAsync() ?? Task.CompletedTask;

            if (_logger.IsInfo)
            {
                _logger.Info("Stopping block producer...");
            }
            Task blockProducerTask = _context.BlockProducer?.StopAsync() ?? Task.CompletedTask;

            if (_logger.IsInfo)
            {
                _logger.Info("Stopping sync peer pool...");
            }
            Task peerPoolTask = _context.SyncPeerPool?.StopAsync() ?? Task.CompletedTask;

            if (_logger.IsInfo)
            {
                _logger.Info("Stopping peer manager...");
            }
            Task peerManagerTask = _context.PeerManager?.StopAsync() ?? Task.CompletedTask;

            if (_logger.IsInfo)
            {
                _logger.Info("Stopping synchronizer...");
            }
            Task synchronizerTask = (_context.Synchronizer?.StopAsync() ?? Task.CompletedTask)
                                    .ContinueWith(t => _context.Synchronizer?.Dispose());

            if (_logger.IsInfo)
            {
                _logger.Info("Stopping blockchain processor...");
            }
            Task blockchainProcessorTask = (_context.BlockchainProcessor?.StopAsync() ?? Task.CompletedTask);

            if (_logger.IsInfo)
            {
                _logger.Info("Stopping rlpx peer...");
            }
            Task rlpxPeerTask = _context.RlpxPeer?.Shutdown() ?? Task.CompletedTask;

            await Task.WhenAll(discoveryStopTask, rlpxPeerTask, peerManagerTask, synchronizerTask, peerPoolTask, blockchainProcessorTask, blockProducerTask);

            while (_context.DisposeStack.Count != 0)
            {
                IAsyncDisposable disposable = _context.DisposeStack.Pop();
                if (_logger.IsDebug)
                {
                    _logger.Debug($"Disposing {disposable.GetType().Name}");
                }
                await disposable.DisposeAsync();
            }

            if (_logger.IsInfo)
            {
                _logger.Info("Closing DBs...");
            }
            _context.DbProvider?.Dispose();

            if (_logger.IsInfo)
            {
                _logger.Info("All DBs closed.");
            }
            if (_logger.IsInfo)
            {
                _logger.Info("Ethereum shutdown complete... please wait for all components to close");
            }
        }
Beispiel #22
0
 /// <summary>
 /// Adds an object to the disposer, where that object only implements IAsyncDisposable. When the disposer is
 /// disposed, so will the object be.
 /// This is not typically recommended, and you should implement IDisposable as well.
 /// </summary>
 /// <param name="instance">The instance.</param>
 /// <remarks>
 /// If this Disposer is disposed of using a synchronous Dispose call, that call will throw an exception.
 /// </remarks>
 public void AddInstanceForAsyncDisposal(IAsyncDisposable instance)
 {
     AddInternal(instance);
 }
        public async Task ArcadeSdkUpdate()
        {
            string testChannelName   = "Test Channel " + _random.Next(int.MaxValue);
            var    sourceRepo        = "arcade";
            var    sourceRepoUri     = "https://github.com/dotnet/arcade";
            var    sourceBranch      = "dependencyflow-tests";
            var    sourceCommit      = "0b36b99e29b1751403e23cfad0a7dff585818051";
            var    sourceBuildNumber = _random.Next(int.MaxValue).ToString();
            ImmutableList <AssetData> sourceAssets = ImmutableList.Create <AssetData>()
                                                     .Add(new AssetData(true)
            {
                Name    = "Microsoft.DotNet.Arcade.Sdk",
                Version = "2.1.0",
            });
            var targetRepo   = "maestro-test2";
            var targetBranch = _random.Next(int.MaxValue).ToString();

            await using AsyncDisposableValue <string> channel = await CreateTestChannelAsync(testChannelName).ConfigureAwait(false);

            await using AsyncDisposableValue <string> sub = await CreateSubscriptionAsync(testChannelName, sourceRepo, targetRepo, targetBranch, "none");

            Build build = await CreateBuildAsync(GetRepoUrl("dotnet", sourceRepo), sourceBranch, sourceCommit, sourceBuildNumber, sourceAssets);

            await using IAsyncDisposable _ = await AddBuildToChannelAsync(build.Id, testChannelName);

            using TemporaryDirectory repo = await CloneRepositoryAsync(targetRepo);

            using (ChangeDirectory(repo.Directory))
            {
                await RunGitAsync("checkout", "-b", targetBranch).ConfigureAwait(false);
                await RunDarcAsync("add-dependency",
                                   "--name", "Microsoft.DotNet.Arcade.Sdk",
                                   "--type", "toolset",
                                   "--repo", sourceRepoUri);
                await RunGitAsync("commit", "-am", "Add dependencies.");

                await using IAsyncDisposable ___ = await PushGitBranchAsync("origin", targetBranch);
                await TriggerSubscriptionAsync(sub.Value);

                PullRequest pr = await WaitForPullRequestAsync(targetRepo, targetBranch);

                StringAssert.AreEqualIgnoringCase($"[{targetBranch}] Update dependencies from dotnet/arcade", pr.Title);

                await CheckoutRemoteRefAsync(pr.MergeCommitSha);

                string dependencies = await RunDarcAsync("get-dependencies");

                string[] dependencyLines = dependencies.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
                Assert.AreEqual(new[]
                {
                    "Name:             Microsoft.DotNet.Arcade.Sdk",
                    "Version:          2.1.0",
                    $"Repo:             {sourceRepoUri}",
                    $"Commit:           {sourceCommit}",
                    "Type:             Toolset",
                    "Pinned:           False",
                }, dependencyLines);

                using TemporaryDirectory arcadeRepo = await CloneRepositoryAsync("dotnet", sourceRepo);

                using (ChangeDirectory(arcadeRepo.Directory))
                {
                    await CheckoutRemoteRefAsync(sourceCommit);
                }

                var arcadeFiles = Directory.EnumerateFileSystemEntries(Path.Join(arcadeRepo.Directory, "eng", "common"),
                                                                       "*", SearchOption.AllDirectories)
                                  .Select(s => s.Substring(arcadeRepo.Directory.Length))
                                  .ToHashSet();
                var repoFiles = Directory.EnumerateFileSystemEntries(Path.Join(repo.Directory, "eng", "common"), "*",
                                                                     SearchOption.AllDirectories)
                                .Select(s => s.Substring(repo.Directory.Length))
                                .ToHashSet();

                Assert.IsEmpty(arcadeFiles.Except(repoFiles));
                Assert.IsEmpty(repoFiles.Except(arcadeFiles));
            }
        }
 /// <summary>
 /// Adds the <paramref name="disposable"/> to the list of items that will get disposed when the
 /// container gets disposed.
 /// </summary>
 /// <remarks>
 /// Instances that are registered for disposal, will be disposed in opposite order of registration and
 /// they are guaranteed to be disposed when <see cref="Container.Dispose()"/> is called (even when
 /// exceptions are thrown). This mimics the behavior of the C# and VB <c>using</c> statements,
 /// where the <see cref="IDisposable.Dispose"/> method is called inside the <c>finally</c> block.
 /// </remarks>
 /// <param name="disposable">The instance that should be disposed when the scope ends.</param>
 /// <exception cref="ArgumentNullException">Thrown when one of the arguments is a null reference.
 /// </exception>
 /// <exception cref="ObjectDisposedException">Thrown when the container has been disposed.</exception>
 public void RegisterForDisposal(IAsyncDisposable disposable) =>
 this.scope.RegisterForDisposal(disposable);