Last active
April 19, 2020 07:47
-
-
Save kyubuns/3b435250bfa8de311253473bb78a4ec3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Dummy | |
{ | |
public static void Run() | |
{ | |
Debug.Log("Run!"); | |
Observable.Timer(TimeSpan.FromSeconds(1)) | |
.Subscribe(x => | |
{ | |
if (Random.Range(0, 2) == 0) Success?.Invoke(); | |
else Failed?.Invoke("エラーメッセージ"); | |
}); | |
} | |
// コメント | |
public static event Action Success; | |
public static event Action<string> Failed; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Result | |
{ | |
public bool Success { get; set; } | |
public string ErrorMessage { get; set; } | |
} | |
public async UniTask<Result> DummyRunWrap() | |
{ | |
var resultTask = Observable.Amb( | |
Observable.FromEvent(x => Dummy.Success += x, x => Dummy.Success -= x) | |
.Select(x => new Result { Success = true, Error = null }), | |
Observable.FromEvent<string>(x => Dummy.Failed += x, x => Dummy.Failed -= x) | |
.Select(x => new Result { Success = false, Error = "message" }) | |
).First().ToUniTask(); | |
Dummy.Run(); | |
return await resultTask; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dummy.Success += () => Debug.Log("成功!"); | |
Dummy.Failed += error => Debug.Log($"失敗... {error}"); | |
Dummy.Run(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var result = await DummyRunWrap(); | |
if (result.Success) Debug.Log("成功!"); | |
else Debug.Log($"失敗... {result.ErrorMessage}"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment