private ValueTask MakeIdle(ISpiffyWorker <T> worker) { idleWorkerQueue.Enqueue(worker); Interlocked.Increment(ref idleWorkers); return(new ValueTask()); }
private async ValueTask MakeIdleOrCleanup(ISpiffyWorker <T> worker) { if (busyWorkerMap.TryRemove(worker.WorkerId, out ISpiffyWorker <T> oldWorker)) { Interlocked.Decrement(ref activeWorkers); } if (worker.Lifetime == Short) { oldWorker.Dispose(); } else { await MakeIdle(worker); } }
private ValueTask StartConsumerPipeline() { _ = Task.Run(async() => { pipelineActive = true; while (await headNetworkBlock.OutputAvailableAsync(cancellationTokenSource.Token)) { TMessage msg = await headNetworkBlock.ReceiveAsync(cancellationTokenSource.Token); ISpiffyWorker <T> worker = await GetAvailableWorker(); _ = worker.RunAsync(msg); } pipelineActive = false; }); return(new ValueTask()); }
ValueTask ISpiffyContext <T> .Reclaim(ISpiffyWorker <T> spiffyWorker) => new ValueTask();
public override async ValueTask Reclaim(ISpiffyWorker <T> spiffyWorker) => await MakeIdleOrCleanup(spiffyWorker);