File tree Expand file tree Collapse file tree 2 files changed +64
-0
lines changed
src/ReactiveMvvm.Terminal Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Original file line number Diff line number Diff line change 11using System ;
2+ using System . Reactive . Concurrency ;
23using ReactiveMvvm . Services ;
34using ReactiveMvvm . Terminal . Services ;
45using ReactiveMvvm . Terminal . Views ;
56using ReactiveMvvm . ViewModels ;
7+ using ReactiveUI ;
68using Terminal . Gui ;
79
810namespace ReactiveMvvm . Terminal
@@ -12,6 +14,8 @@ public static class Program
1214 public static void Main ( string [ ] args )
1315 {
1416 Application . Init ( ) ;
17+ RxApp . MainThreadScheduler = TerminalScheduler . Default ;
18+ RxApp . TaskpoolScheduler = TaskPoolScheduler . Default ;
1519 Application . Run (
1620 new FeedbackView (
1721 new (
Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Reactive . Concurrency ;
3+ using System . Reactive . Disposables ;
4+ using Terminal . Gui ;
5+
6+ namespace ReactiveMvvm ;
7+
8+ public class TerminalScheduler : LocalScheduler
9+ {
10+ public static readonly TerminalScheduler Default = new ( ) ;
11+ private TerminalScheduler ( ) { }
12+
13+ public override IDisposable Schedule < TState > (
14+ TState state ,
15+ TimeSpan dueTime ,
16+ Func < IScheduler , TState , IDisposable > action
17+ )
18+ {
19+ IDisposable PostOnMainLoop ( )
20+ {
21+ var composite = new CompositeDisposable ( 2 ) ;
22+ var cancellation = new CancellationDisposable ( ) ;
23+
24+ Application . Invoke (
25+ ( ) =>
26+ {
27+ if ( ! cancellation . Token . IsCancellationRequested )
28+ {
29+ composite . Add ( action ( this , state ) ) ;
30+ }
31+ }
32+ ) ;
33+ composite . Add ( cancellation ) ;
34+
35+ return composite ;
36+ }
37+
38+ IDisposable PostOnMainLoopAsTimeout ( )
39+ {
40+ var composite = new CompositeDisposable ( 2 ) ;
41+
42+ object timeout = Application . AddTimeout (
43+ dueTime ,
44+ ( ) =>
45+ {
46+ composite . Add ( action ( this , state ) ) ;
47+
48+ return false ;
49+ }
50+ ) ;
51+ composite . Add ( Disposable . Create ( ( ) => Application . RemoveTimeout ( timeout ) ) ) ;
52+
53+ return composite ;
54+ }
55+
56+ return dueTime == TimeSpan . Zero
57+ ? PostOnMainLoop ( )
58+ : PostOnMainLoopAsTimeout ( ) ;
59+ }
60+ }
You can’t perform that action at this time.
0 commit comments