Skip to content

Instantly share code, notes, and snippets.

@acple
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acple/191b6a9c182795b63b2d to your computer and use it in GitHub Desktop.
Save acple/191b6a9c182795b63b2d to your computer and use it in GitHub Desktop.
using System;
using System.Reactive.Linq;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var source = Observable.Return(0) // (int 0)で長さ1
.Do(Console.WriteLine) // 監視用
.Repeat() // 無限リピート
.Take(7); // 適当に切る
source.Subscribe();
// Subscribeが7回目でちゃんとOnCompletedになってるのに
// その後もDoのところでOnNext(0) -> OnCompleted() -> OnNext(0) -> が無限ループして永久ブロック
}
static void Test1()
{
var source = Observable.Range(0, 1) // (int 0)で長さ1
.Do(Console.WriteLine) // 監視用
.Repeat() // 無限リピート
.Take(7); // 適当に切る
source.Subscribe();
// こっちはちゃんと7回でとまる
// この2つはスケジューラの違いでRepeatはImmediate、RangeはCurrentThreadらしいです
// https://twitter.com/neuecc/status/559287415324434433
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment