| @@ -61,11 +61,7 @@ namespace Discord.Commands | |||||
| } | } | ||||
| public CommandBuilder Do(Action<CommandEventArgs> func) | public CommandBuilder Do(Action<CommandEventArgs> func) | ||||
| { | { | ||||
| #if DNXCORE50 | |||||
| _command.Handler = e => { func(e); return Task.CompletedTask; }; | |||||
| #else | |||||
| _command.Handler = e => { func(e); return Task.Delay(0); }; | |||||
| #endif | |||||
| _command.Handler = e => { func(e); return TaskHelper.CompletedTask; }; | |||||
| return this; | return this; | ||||
| } | } | ||||
| } | } | ||||
| @@ -5,6 +5,7 @@ | |||||
| "tags": [ "discord", "discordapp" ], | "tags": [ "discord", "discordapp" ], | ||||
| "projectUrl": "https://github.com/RogueException/Discord.Net", | "projectUrl": "https://github.com/RogueException/Discord.Net", | ||||
| "licenseUrl": "http://opensource.org/licenses/MIT", | "licenseUrl": "http://opensource.org/licenses/MIT", | ||||
| "compile": ["**/*.cs", "../Discord.Net/Shared/*.cs"], | |||||
| "repository": { | "repository": { | ||||
| "type": "git", | "type": "git", | ||||
| "url": "git://github.com/RogueException/Discord.Net" | "url": "git://github.com/RogueException/Discord.Net" | ||||
| @@ -184,8 +184,8 @@ | |||||
| <Compile Include="..\Discord.Net\Helpers\MessageCleaner.cs"> | <Compile Include="..\Discord.Net\Helpers\MessageCleaner.cs"> | ||||
| <Link>Helpers\MessageCleaner.cs</Link> | <Link>Helpers\MessageCleaner.cs</Link> | ||||
| </Compile> | </Compile> | ||||
| <Compile Include="..\Discord.Net\Helpers\TaskHelper.cs"> | |||||
| <Link>Helpers\TaskHelper.cs</Link> | |||||
| <Compile Include="..\Discord.Net\Helpers\TaskExtensions.cs"> | |||||
| <Link>Helpers\TaskExtensions.cs</Link> | |||||
| </Compile> | </Compile> | ||||
| <Compile Include="..\Discord.Net\Mention.cs"> | <Compile Include="..\Discord.Net\Mention.cs"> | ||||
| <Link>Mention.cs</Link> | <Link>Mention.cs</Link> | ||||
| @@ -217,6 +217,9 @@ | |||||
| <Compile Include="..\Discord.Net\Models\User.cs"> | <Compile Include="..\Discord.Net\Models\User.cs"> | ||||
| <Link>Models\User.cs</Link> | <Link>Models\User.cs</Link> | ||||
| </Compile> | </Compile> | ||||
| <Compile Include="..\Discord.Net\Shared\TaskHelper.cs"> | |||||
| <Link>Shared\TaskHelper.cs</Link> | |||||
| </Compile> | |||||
| <Compile Include="..\Discord.Net\TimeoutException.cs"> | <Compile Include="..\Discord.Net\TimeoutException.cs"> | ||||
| <Link>TimeoutException.cs</Link> | <Link>TimeoutException.cs</Link> | ||||
| </Compile> | </Compile> | ||||
| @@ -238,6 +241,9 @@ | |||||
| <Compile Include="..\Discord.Net\WebSockets\Voice\Events.cs"> | <Compile Include="..\Discord.Net\WebSockets\Voice\Events.cs"> | ||||
| <Link>WebSockets\Voice\Events.cs</Link> | <Link>WebSockets\Voice\Events.cs</Link> | ||||
| </Compile> | </Compile> | ||||
| <Compile Include="..\Discord.Net\WebSockets\Voice\VoiceBuffer.cs"> | |||||
| <Link>WebSockets\Voice\VoiceBuffer.cs</Link> | |||||
| </Compile> | |||||
| <Compile Include="..\Discord.Net\WebSockets\Voice\VoiceWebSocket.cs"> | <Compile Include="..\Discord.Net\WebSockets\Voice\VoiceWebSocket.cs"> | ||||
| <Link>WebSockets\Voice\VoiceWebSocket.cs</Link> | <Link>WebSockets\Voice\VoiceWebSocket.cs</Link> | ||||
| </Compile> | </Compile> | ||||
| @@ -2,26 +2,16 @@ | |||||
| using System.Threading; | using System.Threading; | ||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| namespace Discord.Helpers | |||||
| namespace Discord | |||||
| { | { | ||||
| internal static class TaskHelper | |||||
| public static class TaskExtensions | |||||
| { | { | ||||
| public static Task CompletedTask { get; } | |||||
| static TaskHelper() | |||||
| { | |||||
| #if DNXCORE50 | |||||
| CompletedTask = Task.CompletedTask; | |||||
| #else | |||||
| CompletedTask = Task.Delay(0); | |||||
| #endif | |||||
| } | |||||
| public static async Task Timeout(this Task self, int milliseconds) | public static async Task Timeout(this Task self, int milliseconds) | ||||
| { | { | ||||
| Task timeoutTask = Task.Delay(milliseconds); | Task timeoutTask = Task.Delay(milliseconds); | ||||
| Task finishedTask = await Task.WhenAny(self, timeoutTask); | Task finishedTask = await Task.WhenAny(self, timeoutTask); | ||||
| if (finishedTask == timeoutTask) | if (finishedTask == timeoutTask) | ||||
| throw new TimeoutException(); | |||||
| throw new TimeoutException(); | |||||
| else | else | ||||
| await self; | await self; | ||||
| } | } | ||||
| @@ -0,0 +1,17 @@ | |||||
| using System.Threading.Tasks; | |||||
| namespace Discord | |||||
| { | |||||
| internal static class TaskHelper | |||||
| { | |||||
| public static Task CompletedTask { get; } | |||||
| static TaskHelper() | |||||
| { | |||||
| #if DNXCORE50 | |||||
| CompletedTask = Task.CompletedTask; | |||||
| #else | |||||
| CompletedTask = Task.Delay(0); | |||||
| #endif | |||||
| } | |||||
| } | |||||
| } | |||||