Commit 02f3c0be authored by Jeremy Meng's avatar Jeremy Meng

Add extension methods for Stream's APM pattern.

parent 6a304322
......@@ -10,6 +10,7 @@
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StackExchange.Redis
{
......@@ -1078,4 +1079,22 @@ public void CheckForStaleConnection(ref SocketManager.ManagerState managerState)
}
}
}
#if DNXCORE50
internal static class StreamExtensions
{
internal static IAsyncResult BeginRead(this Stream stream, byte[] buffer, int offset, int count, AsyncCallback ac, object state)
{
Task<int> f = stream.ReadAsync(buffer, offset, count);
if (ac != null) f.ContinueWith(res => ac(f));
f.Start();
return f;
}
internal static int EndRead(this Stream stream, IAsyncResult ar)
{
return ((Task<int>)ar).Result;
}
}
#endif
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment