Skip to content

Instantly share code, notes, and snippets.

@kyubuns
Created October 5, 2017 09:39
Show Gist options
  • Save kyubuns/572b95f3b97b125d3270fb5ddeb79d90 to your computer and use it in GitHub Desktop.
Save kyubuns/572b95f3b97b125d3270fb5ddeb79d90 to your computer and use it in GitHub Desktop.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UniRx;
namespace Dev
{
public class Sandbox : MonoBehaviour
{
void Start()
{
Debug.Log("start");
AsyncMessageBroker.Default.Subscribe<TestArgs>(x =>
{
return Observable
.Timer(TimeSpan.FromSeconds(3))
.ForEachAsync(_ => Debug.Log($"1: {x.Value}"));
});
AsyncMessageBroker.Default.Subscribe<TestArgs>(x =>
{
return Observable
.Timer(TimeSpan.FromSeconds(2))
.ForEachAsync(_ => Debug.Log($"2: {x.Value}"));
});
AsyncMessageBroker.Default.Subscribe<IHoge>(x =>
{
return Observable
.Timer(TimeSpan.FromSeconds(1.5f))
.ForEachAsync(_ => Debug.Log($"3: {x.Value}"));
});
AsyncMessageBroker.Default.PublishAsync(new TestArgs{ Value = 3000 })
.Subscribe(_ =>
{
UnityEngine.Debug.Log("called all subscriber completed");
});
}
}
public interface IHoge
{
int Value { get; }
}
public class TestArgs : IHoge
{
public int Value { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment