IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
ExecutorTaskScheduler.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
4
5#if FIRST_PASS == false
6
7using java.lang;
8using java.util.concurrent;
9
11{
12
16 class ExecutorTaskScheduler : TaskScheduler
17 {
18
22 class TaskRunnable : Runnable
23 {
24
25 readonly ExecutorTaskScheduler scheduler;
26 readonly Task task;
27
34 public TaskRunnable(ExecutorTaskScheduler scheduler, Task task)
35 {
36 this.scheduler = scheduler ?? throw new ArgumentNullException(nameof(scheduler));
37 this.task = task ?? throw new ArgumentNullException(nameof(task));
38 }
39
40 public void run()
41 {
42 scheduler.TryExecuteTask(task);
43 }
44
45 }
46
47 readonly Executor executor;
48
54 public ExecutorTaskScheduler(Executor executor)
55 {
56 this.executor = executor ?? throw new ArgumentNullException(nameof(executor));
57 }
58
59 protected override void QueueTask(Task task)
60 {
61 executor.execute(new TaskRunnable(this, task));
62 }
63
64 protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
65 {
66 return TryExecuteTask(task);
67 }
68
69 protected override IEnumerable<Task> GetScheduledTasks()
70 {
71 return Array.Empty<Task>();
72 }
73
74 }
75
76}
77
78#endif
TaskScheduler implementation that executes tasks on a Executor.
ExecutorTaskScheduler(Executor executor)
Initializes a new instance.
override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)