Skip to content
This repository was archived by the owner on Feb 16, 2024. It is now read-only.

Commit 66205df

Browse files
committed
fix await behaviour of ReactivePropery/ReactiveCommand #419
1 parent 0cb5009 commit 66205df

File tree

5 files changed

+58
-14
lines changed

5 files changed

+58
-14
lines changed

Assets/Plugins/UniRx/Scripts/UnityEngineBridge/ReactiveCommand.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,14 @@ static void CancelCallback(object state)
337337
{
338338
var tcs = new CancellableTaskCompletionSource<T>();
339339

340-
var subscription = source.Subscribe(x => tcs.TrySetResult(x), ex => tcs.TrySetException(ex), () => tcs.TrySetCanceled());
341-
cancellationToken.Register(Callback, Tuple.Create(tcs, subscription), false);
340+
var disposable = new SingleAssignmentDisposable();
341+
disposable.Disposable = source.Subscribe(x =>
342+
{
343+
disposable.Dispose(); // finish subscription.
344+
tcs.TrySetResult(x);
345+
}, ex => tcs.TrySetException(ex), () => tcs.TrySetCanceled());
346+
347+
cancellationToken.Register(Callback, Tuple.Create(tcs, disposable.Disposable), false);
342348

343349
return tcs.Task;
344350
}

Assets/Plugins/UniRx/Scripts/UnityEngineBridge/ReactiveProperty.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,35 @@ static void CancelCallback(object state)
506506
{
507507
var tcs = new CancellableTaskCompletionSource<T>();
508508

509-
var subscription = source.Subscribe(x => tcs.TrySetResult(x), ex => tcs.TrySetException(ex), () => tcs.TrySetCanceled());
510-
cancellationToken.Register(Callback, Tuple.Create(tcs, subscription), false);
509+
var disposable = new SingleAssignmentDisposable();
510+
if (source.HasValue)
511+
{
512+
// Skip first value
513+
var isFirstValue = true;
514+
disposable.Disposable = source.Subscribe(x =>
515+
{
516+
if (isFirstValue)
517+
{
518+
isFirstValue = false;
519+
return;
520+
}
521+
else
522+
{
523+
disposable.Dispose(); // finish subscription.
524+
tcs.TrySetResult(x);
525+
}
526+
}, ex => tcs.TrySetException(ex), () => tcs.TrySetCanceled());
527+
}
528+
else
529+
{
530+
disposable.Disposable = source.Subscribe(x =>
531+
{
532+
disposable.Dispose(); // finish subscription.
533+
tcs.TrySetResult(x);
534+
}, ex => tcs.TrySetException(ex), () => tcs.TrySetCanceled());
535+
}
536+
537+
cancellationToken.Register(Callback, Tuple.Create(tcs, disposable.Disposable), false);
511538

512539
return tcs.Task;
513540
}

Assets/Scripts/Sandbox/SandboxScene.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,23 @@ public class SandboxScene : MonoBehaviour
1212
public Button buttonA;
1313
public Button buttonB;
1414
// MyMyClass mc;
15-
ReactiveProperty<int> rp = new ReactiveProperty<int>();
15+
//ReactiveProperty<int> rp = new ReactiveProperty<int>();
16+
17+
18+
//public async void Start()
19+
//{
20+
// rp.Value = 10;
21+
22+
// buttonA.onClick.AddListener(() =>
23+
// {
24+
// rp.Value = 99;
25+
// });
26+
27+
// Debug.Log("Begin:" + rp.Value);
28+
// var v= await rp;
29+
// Debug.Log("End:" + v);
30+
//}
1631

17-
1832
}
1933

2034
public class MyMyClass

Assets/Scripts/UnityTests/Rx/ReactivePropertyTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
using System.Linq;
44
using System.Text;
55
using NUnit.Framework;
6+
using UnityEngine.TestTools;
67

78
namespace UniRx.Tests
89
{
9-
10+
1011
public class ReactivePropertyTest
1112
{
1213
[Test]

ProjectSettings/ProjectSettings.asset

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
--- !u!129 &1
44
PlayerSettings:
55
m_ObjectHideFlags: 0
6-
serializedVersion: 17
6+
serializedVersion: 16
77
productGUID: b286933f5059e50428b251ea31eb0f32
88
AndroidProfiler: 0
99
AndroidFilterTouchesWhenObscured: 0
@@ -65,7 +65,6 @@ PlayerSettings:
6565
disableDepthAndStencilBuffers: 0
6666
androidStartInFullscreen: 1
6767
androidRenderOutsideSafeArea: 1
68-
androidUseSwappy: 0
6968
androidBlitType: 0
7069
defaultIsNativeResolution: 1
7170
macRetinaSupport: 1
@@ -149,7 +148,6 @@ PlayerSettings:
149148
oculus:
150149
sharedDepthBuffer: 0
151150
dashSupport: 0
152-
lowOverheadMode: 0
153151
enable360StereoCapture: 0
154152
isWsaHolographicRemotingEnabled: 0
155153
protectGraphicsMemory: 0
@@ -274,8 +272,6 @@ PlayerSettings:
274272
height: 180
275273
banner: {fileID: 0}
276274
androidGamepadSupportLevel: 0
277-
AndroidValidateAppBundleSize: 1
278-
AndroidAppBundleSizeToValidate: 100
279275
resolutionDialogBanner: {fileID: 0}
280276
m_BuildTargetIcons:
281277
- m_BuildTarget:
@@ -515,7 +511,6 @@ PlayerSettings:
515511
monoEnv:
516512
splashScreenBackgroundSourceLandscape: {fileID: 0}
517513
splashScreenBackgroundSourcePortrait: {fileID: 0}
518-
blurSplashScreenBackground: 1
519514
spritePackerPolicy:
520515
webGLMemorySize: 256
521516
webGLExceptionSupport: 0
@@ -536,7 +531,7 @@ PlayerSettings:
536531
platformArchitecture:
537532
iPhone: 2
538533
scriptingBackend:
539-
Standalone: 1
534+
Standalone: 0
540535
WP8: 2
541536
WebGL: 1
542537
Windows Store Apps: 2
@@ -603,6 +598,7 @@ PlayerSettings:
603598
XboxOneAllowedProductIds: []
604599
XboxOnePersistentLocalStorageSize: 0
605600
XboxOneXTitleMemory: 8
601+
xboxOneScriptCompiler: 1
606602
XboxOneOverrideIdentityName:
607603
vrEditorSettings:
608604
daydream:

0 commit comments

Comments
 (0)