@@ -31,8 +31,8 @@ public static class AsyncOperationHelper
31
31
/// </param>
32
32
public static void Post ( [ NotNull ] this AsyncOperation asyncOp , [ NotNull , InstantHandle ] Action runner )
33
33
{
34
- if ( asyncOp == null ) throw new ArgumentNullException ( nameof ( asyncOp ) ) ;
35
- if ( runner == null ) throw new ArgumentNullException ( nameof ( runner ) ) ;
34
+ Code . NotNull ( asyncOp , nameof ( asyncOp ) ) ;
35
+ Code . NotNull ( runner , nameof ( runner ) ) ;
36
36
asyncOp . Post ( state => runner ( ) , null ) ;
37
37
}
38
38
@@ -41,12 +41,10 @@ public static void Post([NotNull] this AsyncOperation asyncOp, [NotNull, Instant
41
41
/// </summary>
42
42
/// <param name="asyncOp"></param>
43
43
/// <param name="runner">A <see cref="Action"/> that wraps the delegate to be called when the operation ends.</param>
44
- public static void PostOperationCompleted (
45
- [ NotNull ] this AsyncOperation asyncOp ,
46
- [ NotNull , InstantHandle ] Action runner )
44
+ public static void PostOperationCompleted ( [ NotNull ] this AsyncOperation asyncOp , [ NotNull , InstantHandle ] Action runner )
47
45
{
48
- if ( asyncOp == null ) throw new ArgumentNullException ( nameof ( asyncOp ) ) ;
49
- if ( runner == null ) throw new ArgumentNullException ( nameof ( runner ) ) ;
46
+ Code . NotNull ( asyncOp , nameof ( asyncOp ) ) ;
47
+ Code . NotNull ( runner , nameof ( runner ) ) ;
50
48
asyncOp . PostOperationCompleted ( state => runner ( ) , null ) ;
51
49
}
52
50
@@ -58,7 +56,7 @@ public static void PostOperationCompleted(
58
56
/// <param name="runner">
59
57
/// A <see cref="Action"/> that wraps the delegate to be called when the operation ends.
60
58
/// </param>
61
- public static void Send ( [ NotNull ] this AsyncOperation asyncOp , [ NotNull ] Action runner )
59
+ public static void Send ( [ NotNull ] this AsyncOperation asyncOp , [ NotNull , InstantHandle ] Action runner )
62
60
{
63
61
if ( asyncOp == null ) throw new ArgumentNullException ( nameof ( asyncOp ) ) ;
64
62
if ( runner == null ) throw new ArgumentNullException ( nameof ( runner ) ) ;
@@ -75,10 +73,11 @@ public static void Send([NotNull] this AsyncOperation asyncOp, [NotNull] Action
75
73
/// A <see cref="Func{TResult}"/> that wraps the delegate to be called when the operation ends.
76
74
/// </param>
77
75
/// <returns>Result of <paramref name="runner"/> execution.</returns>
78
- public static T Send < T > ( [ NotNull ] this AsyncOperation asyncOp , [ NotNull ] Func < T > runner )
76
+ public static T Send < T > ( [ NotNull ] this AsyncOperation asyncOp , [ NotNull , InstantHandle ] Func < T > runner )
79
77
{
80
- if ( asyncOp == null ) throw new ArgumentNullException ( nameof ( asyncOp ) ) ;
81
- if ( runner == null ) throw new ArgumentNullException ( nameof ( runner ) ) ;
78
+ Code . NotNull ( asyncOp , nameof ( asyncOp ) ) ;
79
+ Code . NotNull ( runner , nameof ( runner ) ) ;
80
+
82
81
var result = default ( T ) ;
83
82
asyncOp . SynchronizationContext . Send ( state => result = runner ( ) , null ) ;
84
83
return result ;
@@ -87,11 +86,10 @@ public static T Send<T>([NotNull] this AsyncOperation asyncOp, [NotNull] Func<T>
87
86
/// <summary>
88
87
/// Gets thread from pool and run <paramref name="runner"/> inside it.
89
88
/// </summary>
90
- /// <param name="runner">Action to run inside created thread</param>
91
- public static void RunAsync ( [ NotNull ] Action < AsyncOperation > runner )
89
+ /// <param name="runner">Action to run inside created thread. </param>
90
+ public static void RunAsync ( [ NotNull , InstantHandle ] Action < AsyncOperation > runner )
92
91
{
93
- if ( runner == null )
94
- throw new ArgumentNullException ( nameof ( runner ) ) ;
92
+ Code . NotNull ( runner , nameof ( runner ) ) ;
95
93
96
94
var asyncOp = CreateOperation ( ) ;
97
95
ThreadPool . QueueUserWorkItem ( state => runner ( asyncOp ) ) ;
@@ -100,18 +98,16 @@ public static void RunAsync([NotNull] Action<AsyncOperation> runner)
100
98
/// <summary>
101
99
/// Gets thread from pool and run <paramref name="runner"/> inside it.
102
100
/// </summary>
103
- /// <param name="runner">Action to run inside created thread</param>
101
+ /// <param name="runner">Action to run inside created thread. </param>
104
102
/// <param name="completeHandler">
105
103
/// Action called after <paramref name="runner"/> complete execution. Synchronized with method calling thread.
106
104
/// </param>
107
105
public static void RunAsync (
108
- Action < AsyncOperation > runner ,
109
- Action completeHandler )
106
+ [ NotNull , InstantHandle ] Action < AsyncOperation > runner ,
107
+ [ NotNull , InstantHandle ] Action completeHandler )
110
108
{
111
- if ( runner == null )
112
- throw new ArgumentNullException ( nameof ( runner ) ) ;
113
- if ( completeHandler == null )
114
- throw new ArgumentNullException ( nameof ( completeHandler ) ) ;
109
+ Code . NotNull ( runner , nameof ( runner ) ) ;
110
+ Code . NotNull ( completeHandler , nameof ( completeHandler ) ) ;
115
111
116
112
var asyncOp = CreateOperation ( ) ;
117
113
ThreadPool . QueueUserWorkItem (
0 commit comments