mirror of
				https://github.com/esiur/esiur-dotnet.git
				synced 2025-10-30 23:51:34 +00:00 
			
		
		
		
	Rename
This commit is contained in:
		
							
								
								
									
										53
									
								
								Esiur/Core/AsyncAwaiterGeneric.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								Esiur/Core/AsyncAwaiterGeneric.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,53 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Runtime.CompilerServices; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
|  | ||||
| namespace Esiur.Core | ||||
| { | ||||
|     public class AsyncAwaiter<T> : INotifyCompletion | ||||
|     { | ||||
|         Action callback = null; | ||||
|  | ||||
|         AsyncException exception = null; | ||||
|  | ||||
|         T result; | ||||
|  | ||||
|         public AsyncAwaiter(AsyncReply<T> reply) | ||||
|         { | ||||
|             reply.Then(x => | ||||
|             { | ||||
|                 this.IsCompleted = true; | ||||
|                 this.result = (T)x; | ||||
|                 this.callback?.Invoke(); | ||||
|             }).Error(x => | ||||
|             { | ||||
|                 exception = x; | ||||
|                 this.IsCompleted = true; | ||||
|                 this.callback?.Invoke(); | ||||
|             }); | ||||
|         } | ||||
|  | ||||
|         public T GetResult() | ||||
|         { | ||||
|             if (exception != null) | ||||
|                 throw exception; | ||||
|             return result; | ||||
|         } | ||||
|  | ||||
|         public bool IsCompleted { get; private set; } | ||||
|  | ||||
|         public void OnCompleted(Action continuation) | ||||
|         { | ||||
|             if (IsCompleted) | ||||
|                 continuation?.Invoke(); | ||||
|             else | ||||
|                 // Continue.... | ||||
|                 callback = continuation; | ||||
|         } | ||||
|  | ||||
|  | ||||
|     } | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user