-
Notifications
You must be signed in to change notification settings - Fork 8
/
RNPromise.cs
63 lines (54 loc) · 1.38 KB
/
RNPromise.cs
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using Newtonsoft.Json;
using UnityEngine;
namespace RNUnity
{
public class RNPromise
{
public object handle;
public static RNPromise Begin(object param)
{
return RNPromise<object>.Begin(param);
}
public void Reject<TReason>(TReason reason)
{
RNBridge.EmitEvent("reject", new {
handle = handle,
reason = reason
});
}
public void Resolve<TRetval>(TRetval retval)
{
RNBridge.EmitEvent("resolve", new {
handle = handle,
retval = retval
});
}
public void Resolve()
{
RNBridge.EmitEvent("resolve", new {
handle = handle
});
}
}
public class RNPromise<T> : RNPromise
{
public T input;
public static new RNPromise<T> Begin(object param)
{
if (Debug.isDebugBuild)
Debug.Log($"{nameof(RNPromise)}: begin");
try
{
return JsonConvert.DeserializeObject<RNPromise<T>>(
(string) param
);
}
catch (Exception e)
{
Debug.LogError($"{nameof(RNPromise)}: {e.Message}");
return new RNPromise<T>();
}
}
}
}