Skip to content

Commit

Permalink
Clothes fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zziger committed Sep 25, 2023
1 parent 0ed3555 commit 91cf5dc
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Concurrent;
using AltV.Net;
using AltV.Net.Elements.Entities;

Expand Down Expand Up @@ -38,19 +39,17 @@ private void PushId(long id)
internal static class ClothesFitService
{
private static readonly IdGenerator _idGen = new();
private static readonly Dictionary<long, TaskCompletionSource<object>> _tasks = new();
private static readonly ConcurrentDictionary<long, TaskCompletionSource<object>> _tasks = new();

static ClothesFitService()
{
Alt.OnServer("clothes.resp", (long id, string type, object result) =>
{
if (!_tasks.TryGetValue(id, out var tcs))
if (!_tasks.TryRemove(id, out var tcs))
{
return;
}

_tasks.Remove(id);

if (type == "error")
{
tcs.TrySetException(new Exception(result?.ToString()));
Expand Down Expand Up @@ -98,7 +97,7 @@ public static async Task<ulong[]> GetOutfitsBySex(uint sex)
{
var tcs = new TaskCompletionSource<object>();
var id = _idGen.GetNextId();
_tasks.Add(id, tcs);
_tasks.TryAdd(id, tcs);
Alt.Emit("clothes.req", null, "getoutfits", id, sex);
var result = await tcs.Task;
return ((object[]) result).Select(Convert.ToUInt64).ToArray();
Expand All @@ -108,7 +107,7 @@ private static Task MakeReq(IPlayer player, string eventName, params object[] ar
{
var tcs = new TaskCompletionSource<object>();
var id = _idGen.GetNextId();
_tasks.Add(id, tcs);
_tasks.TryAdd(id, tcs);
Alt.Emit("clothes.req", player, eventName, id, args);
return tcs.Task;
}
Expand Down

0 comments on commit 91cf5dc

Please sign in to comment.