public override Task FlushAsync (CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
- return Task<int>.Canceled;
+ return TaskConstants<int>.Canceled;
Flush ();
- return Task.Finished;
+ return TaskConstants.Finished;
}
public override Task<int> ReadAsync (byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
- return Task<int>.Canceled;
+ return TaskConstants<int>.Canceled;
count = Read (buffer, offset, count);
public override Task WriteAsync (byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
- return Task<int>.Canceled;
+ return TaskConstants<int>.Canceled;
Write (buffer, offset, count);
- return Task.Finished;
+ return TaskConstants.Finished;
}
#endif
}
public virtual Task FlushAsync (CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
- return Task.Canceled;
+ return TaskConstants.Canceled;
var t = new Task (() => Flush (), cancellationToken);
t.Start ();
public virtual Task<int> ReadAsync (byte[] buffer, int offset, int count, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
- return Task<int>.Canceled;
+ return TaskConstants<int>.Canceled;
return Task<int>.Factory.FromAsync (BeginRead, EndRead, buffer, offset, count, null);
}
static int id = -1;
static readonly TaskFactory defaultFactory = new TaskFactory ();
- internal static readonly Task Finished = new Task (TaskStatus.RanToCompletion);
- internal static readonly Task Canceled = new Task (TaskStatus.Canceled);
CountdownEvent childTasks;
parent.AddChild ();
}
- internal Task (TaskStatus status)
- {
- this.status = status;
- }
-
~Task ()
{
if (exception != null && !exceptionObserved)
public static Task<TResult> FromResult<TResult> (TResult result)
{
- var t = new Task<TResult> (TaskStatus.RanToCompletion);
- t.Result = result;
- return t;
+ var tcs = new TaskCompletionSource<TResult> ();
+ tcs.SetResult (result);
+ return tcs.Task;
}
public TaskAwaiter GetAwaiter ()
--- /dev/null
+//
+// TaskConstants.cs
+//
+// Authors:
+// Jérémie Laval <jeremie dot laval at xamarin dot com>
+//
+// Copyright 2011 Xamarin Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+//
+
+#if NET_4_5
+using System;
+using System.Runtime.CompilerServices;
+
+namespace System.Threading.Tasks
+{
+ internal class TaskConstants
+ {
+ internal static readonly Task Finished = InitCompleted ();
+ internal static readonly Task Canceled = InitCanceled ();
+
+ static Task InitCompleted ()
+ {
+ var tcs = new TaskCompletionSource<object> ();
+ tcs.SetResult (null);
+ return tcs.Task;
+ }
+
+ static Task InitCanceled ()
+ {
+ var tcs = new TaskCompletionSource<object> ();
+ tcs.SetCanceled ();
+ return tcs.Task;
+ }
+ }
+}
+
+#endif
--- /dev/null
+//
+// TaskConstants_T.cs
+//
+// Authors:
+// Jérémie Laval <jeremie dot laval at xamarin dot com>
+//
+// Copyright 2011 Xamarin Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+//
+
+#if NET_4_5 || MOBILE
+using System;
+using System.Runtime.CompilerServices;
+
+namespace System.Threading.Tasks
+{
+ internal class TaskConstants<T>
+ {
+ internal static readonly Task<T> Canceled;
+
+ static TaskConstants ()
+ {
+ var tcs = new TaskCompletionSource<T> ();
+ tcs.SetCanceled ();
+ Canceled = tcs.Task;
+ }
+ }
+}
+
+#endif
[System.Diagnostics.DebuggerTypeProxy (typeof (TaskDebuggerView))]
public class Task<TResult> : Task
{
- internal static new readonly Task<TResult> Canceled = new Task<TResult> (TaskStatus.Canceled);
static readonly TaskFactory<TResult> factory = new TaskFactory<TResult> ();
static readonly Action<object> emptyAction = delegate (object o) {};
TResult value;
- internal Func<object, TResult> function;
+ Func<object, TResult> function;
Func<TResult> simpleFunction;
object state;
this.function = function;
this.state = state;
}
-
-
- internal Task (TaskStatus status)
- : base (status)
- {
- }
internal override void InnerInvoke ()
{
System.Threading.Tasks/TaskDebuggerView.cs
System.Threading.Tasks/TaskCompletionSource.cs
System.Threading.Tasks/TaskSchedulerException.cs
+System.Threading.Tasks/TaskConstants.cs
+System.Threading.Tasks/TaskConstants_T.cs
System.Collections.Concurrent/OrderablePartitioner.cs
System.Collections.Concurrent/ConcurrentDictionary.cs
System.Collections.Concurrent/Partitioner.cs