Skip to content

Commit

Permalink
Use .NET 9 features: Lock and Index()
Browse files Browse the repository at this point in the history
  • Loading branch information
jerry08 committed Oct 3, 2024
1 parent 986b437 commit 9e84d19
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Yosu.Youtube.Converter/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private async ValueTask ProcessAsync(
}

// Metadata for subtitles
foreach (var (subtitleInput, i) in subtitleInputs.WithIndex())
foreach (var (i, subtitleInput) in subtitleInputs.Index())
{
// Language codes can be stored in any format, but most players expect
// three-letter codes, so we'll try to convert to that first.
Expand Down
13 changes: 0 additions & 13 deletions Yosu.Youtube.Converter/Utils/Extensions/CollectionExtensions.cs

This file was deleted.

7 changes: 4 additions & 3 deletions Yosu.Youtube.Converter/Utils/ProgressMuxer.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
using System;
using System.Collections.Generic;
using System.Threading;

namespace Yosu.Youtube.Converter.Utils;

internal class ProgressMuxer(IProgress<double> target)
{
private readonly object _lock = new();
private readonly Lock _lock = new();
private readonly Dictionary<int, double> _splitWeights = new();
private readonly Dictionary<int, double> _splitValues = new();

public IProgress<double> CreateInput(double weight = 1)
{
lock (_lock)
using (_lock.EnterScope())
{
var index = _splitWeights.Count;

Expand All @@ -20,7 +21,7 @@ public IProgress<double> CreateInput(double weight = 1)

return new Progress<double>(p =>
{
lock (_lock)
using (_lock.EnterScope())
{
_splitValues[index] = p;

Expand Down

0 comments on commit 9e84d19

Please sign in to comment.