/
NSRunloopScheduler.cs
47 lines (41 loc) · 1.14 KB
/
NSRunloopScheduler.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
using System;
using System.Linq;
using System.Collections.Generic;
using System.Concurrency;
using System.Disposables;
using MonoTouch.UIKit;
using MonoTouch.Foundation;
namespace ReactiveUI
{
public class NSRunloopScheduler : IScheduler, IEnableLogger
{
NSObject theApp;
#if IOS
public NSRunloopScheduler (UIApplication app)
{
theApp = app;
}
#else
public NSRunloopScheduler (NSApplication app)
{
theApp = app;
}
#endif
public DateTimeOffset Now {
get { return DateTimeOffset.Now; }
}
public IDisposable Schedule(Action action)
{
this.Log().Debug("Scheduling on Runloop");
theApp.BeginInvokeOnMainThread(new NSAction(action));
return Disposable.Empty;
}
public IDisposable Schedule(Action action, TimeSpan dueTime)
{
this.Log().Debug("Scheduling on Runloop");
var timer = NSTimer.CreateScheduledTimer(dueTime, new NSAction(action));
return Disposable.Create(() => timer.Invalidate());
}
}
}
// vim: tw=120 ts=4 sw=4 et :