Compare commits
1 commit
| Author | SHA1 | Date | |
|---|---|---|---|
| 2576a8cc37 |
2 changed files with 15 additions and 3 deletions
|
|
@ -23,7 +23,7 @@ namespace PlaytimeHistory;
|
||||||
public class PlaytimeHistory : BasePlugin, IPluginConfig<PlaytimeHistoryConfig>
|
public class PlaytimeHistory : BasePlugin, IPluginConfig<PlaytimeHistoryConfig>
|
||||||
{
|
{
|
||||||
public override string ModuleName => "PlaytimeHistory";
|
public override string ModuleName => "PlaytimeHistory";
|
||||||
public override string ModuleVersion => "0.2.0";
|
public override string ModuleVersion => "0.2.1";
|
||||||
public override string ModuleAuthor => "astra";
|
public override string ModuleAuthor => "astra";
|
||||||
public override string ModuleDescription => "Records playtime per session, team and alive/dead state";
|
public override string ModuleDescription => "Records playtime per session, team and alive/dead state";
|
||||||
|
|
||||||
|
|
|
||||||
16
Writer.cs
16
Writer.cs
|
|
@ -38,7 +38,9 @@ public sealed class Writer
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Queued => _queue.Reader.Count;
|
// Kept here: a single-reader unbounded channel can't count itself (Reader.Count throws).
|
||||||
|
private int _queued;
|
||||||
|
public int Queued => Volatile.Read(ref _queued);
|
||||||
public int Spooled => _spooled;
|
public int Spooled => _spooled;
|
||||||
public bool Migrated => Volatile.Read(ref _migrated);
|
public bool Migrated => Volatile.Read(ref _migrated);
|
||||||
public bool Failing => Volatile.Read(ref _failing);
|
public bool Failing => Volatile.Read(ref _failing);
|
||||||
|
|
@ -48,7 +50,11 @@ public sealed class Writer
|
||||||
public void Start() => _loop = Task.Run(RunAsync);
|
public void Start() => _loop = Task.Run(RunAsync);
|
||||||
|
|
||||||
// From the game thread. Never blocks.
|
// From the game thread. Never blocks.
|
||||||
public void Enqueue(Op op) => _queue.Writer.TryWrite(op);
|
public void Enqueue(Op op)
|
||||||
|
{
|
||||||
|
if (_queue.Writer.TryWrite(op))
|
||||||
|
Interlocked.Increment(ref _queued);
|
||||||
|
}
|
||||||
|
|
||||||
// On unload: sends what's queued, waiting up to `timeout`, then spools anything left.
|
// On unload: sends what's queued, waiting up to `timeout`, then spools anything left.
|
||||||
public void Drain(TimeSpan timeout)
|
public void Drain(TimeSpan timeout)
|
||||||
|
|
@ -66,8 +72,11 @@ public sealed class Writer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (_queue.Reader.TryRead(out var op))
|
while (_queue.Reader.TryRead(out var op))
|
||||||
|
{
|
||||||
|
Interlocked.Decrement(ref _queued);
|
||||||
Spool(op);
|
Spool(op);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async Task RunAsync()
|
private async Task RunAsync()
|
||||||
{
|
{
|
||||||
|
|
@ -87,7 +96,10 @@ public sealed class Writer
|
||||||
}
|
}
|
||||||
|
|
||||||
while (_queue.Reader.TryRead(out var op))
|
while (_queue.Reader.TryRead(out var op))
|
||||||
|
{
|
||||||
|
Interlocked.Decrement(ref _queued);
|
||||||
await HandleAsync(op, token);
|
await HandleAsync(op, token);
|
||||||
|
}
|
||||||
|
|
||||||
bool more;
|
bool more;
|
||||||
try
|
try
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue