forked from FabianTerhorst/coreclr-module
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAsyncContextExtensions.cs
More file actions
39 lines (34 loc) · 1.24 KB
/
AsyncContextExtensions.cs
File metadata and controls
39 lines (34 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Threading;
using AltV.Net.Elements.Entities;
namespace AltV.Net.Async
{
public static class AsyncContextExtensions
{
public static bool CheckIfExistsNullable(this IAsyncContext context, IBaseObject baseObject)
{
if (context == null) return baseObject.Exists;
return context.CheckIfExists(baseObject);
}
public static bool CheckIfExistsNullable(this IAsyncContext context, IWorldObject worldObject)
{
if (context == null) return worldObject.Exists;
return context.CheckIfExists(worldObject);
}
public static bool CheckIfExistsNullable(this IAsyncContext context, IEntity entity)
{
if (context == null) return entity.Exists;
return context.CheckIfExists(entity);
}
public static void RunOnMainThreadBlockingNullable(this IAsyncContext context, Action action)
{
if (context == null)
{
using var semaphore = new SemaphoreSlim(0, 1);
AltAsync.RunOnMainThreadBlocking(action, semaphore);
return;
}
context.RunOnMainThreadBlocking(action);
}
}
}