Browse Source

Removed Mixed RunMode

tags/1.0-rc
RogueException 8 years ago
parent
commit
ba07484fe9
2 changed files with 19 additions and 36 deletions
  1. +19
    -35
      src/Discord.Net.Commands/Info/CommandInfo.cs
  2. +0
    -1
      src/Discord.Net.Commands/RunMode.cs

+ 19
- 35
src/Discord.Net.Commands/Info/CommandInfo.cs View File

@@ -137,47 +137,15 @@ namespace Discord.Commands
return ExecuteResult.FromError(result); return ExecuteResult.FromError(result);
} }


await Module.Service._cmdLogger.DebugAsync($"Executing {GetLogText(context)}").ConfigureAwait(false);
switch (RunMode) switch (RunMode)
{ {
case RunMode.Sync: //Always sync case RunMode.Sync: //Always sync
try
{
await _action(context, args, map).ConfigureAwait(false);
}
catch (Exception ex)
{
ex = new CommandException(this, context, ex);
await Module.Service._cmdLogger.ErrorAsync(ex).ConfigureAwait(false);
throw;
}
await Module.Service._cmdLogger.VerboseAsync($"Executed {GetLogText(context)}").ConfigureAwait(false);
break;
case RunMode.Mixed: //Sync until first await statement
var t1 = _action(context, args, map).ContinueWith(async t =>
{
if (t.IsFaulted)
{
var ex = new CommandException(this, context, t.Exception);
await Module.Service._cmdLogger.ErrorAsync(ex).ConfigureAwait(false);
}
else
await Module.Service._cmdLogger.VerboseAsync($"Executed {GetLogText(context)}").ConfigureAwait(false);
});
var t1 = ExecuteAsyncInternal(context, args, map);
break; break;
case RunMode.Async: //Always async case RunMode.Async: //Always async
var t2 = Task.Run(() =>
var t2 = Task.Run(async () =>
{ {
var _ = _action(context, args, map).ContinueWith(async t =>
{
if (t.IsFaulted)
{
var ex = new CommandException(this, context, t.Exception);
await Module.Service._cmdLogger.ErrorAsync(ex).ConfigureAwait(false);
}
else
await Module.Service._cmdLogger.VerboseAsync($"Executed {GetLogText(context)}").ConfigureAwait(false);
});
await ExecuteAsyncInternal(context, args, map).ConfigureAwait(false);
}); });
break; break;
} }
@@ -189,6 +157,22 @@ namespace Discord.Commands
} }
} }


private async Task ExecuteAsyncInternal(ICommandContext context, object[] args, IDependencyMap map)
{
await Module.Service._cmdLogger.DebugAsync($"Executing {GetLogText(context)}").ConfigureAwait(false);
try
{
await _action(context, args, map).ConfigureAwait(false);
}
catch (Exception ex)
{
ex = new CommandException(this, context, ex);
await Module.Service._cmdLogger.ErrorAsync(ex).ConfigureAwait(false);
throw;
}
await Module.Service._cmdLogger.VerboseAsync($"Executed {GetLogText(context)}").ConfigureAwait(false);
}

private object[] GenerateArgs(IEnumerable<object> argList, IEnumerable<object> paramsList) private object[] GenerateArgs(IEnumerable<object> argList, IEnumerable<object> paramsList)
{ {
int argCount = Parameters.Count; int argCount = Parameters.Count;


+ 0
- 1
src/Discord.Net.Commands/RunMode.cs View File

@@ -4,7 +4,6 @@
{ {
Default, Default,
Sync, Sync,
Mixed,
Async Async
} }
} }

Loading…
Cancel
Save