Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 13 additions & 26 deletions src/Polyfill/Polyfill_Task.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,29 +124,20 @@ public static ConfiguredTaskAwaitable ConfigureAwait(this Task target, Configure

if ((options & ConfigureAwaitOptions.ForceYielding) != 0)
{
task = ForceYieldAsync(task);

static async Task ForceYieldAsync(Task t)
{
await Task.Yield();
await t;
}
// Task.Run always queues to the thread pool, so the current SynchronizationContext is never captured.
var inner = task;
task = Task.Run(() => inner);
}

if ((options & ConfigureAwaitOptions.SuppressThrowing) != 0)
{
task = SuppressThrowAsync(task);

static async Task SuppressThrowAsync(Task t)
{
try
{
await t;
}
catch
{
}
}
// The continuation completes successfully whatever the outcome of the antecedent.
// Reading Exception marks it as observed, without the cost of a throw and catch.
task = task.ContinueWith(
static antecedent => { _ = antecedent.Exception; },
CancellationToken.None,
TaskContinuationOptions.ExecuteSynchronously,
TaskScheduler.Default);
}

return task.ConfigureAwait(
Expand All @@ -169,13 +160,9 @@ public static ConfiguredTaskAwaitable<TResult> ConfigureAwait<TResult>(

if ((options & ConfigureAwaitOptions.ForceYielding) != 0)
{
task = ForceYieldAsync(task);

static async Task<TResult> ForceYieldAsync(Task<TResult> t)
{
await Task.Yield();
return await t;
}
// Task.Run always queues to the thread pool, so the current SynchronizationContext is never captured.
var inner = task;
task = Task.Run(() => inner);
}

return task.ConfigureAwait(
Expand Down
32 changes: 9 additions & 23 deletions src/Split/net461/Polyfill_Task.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,16 @@ public static ConfiguredTaskAwaitable ConfigureAwait(this Task target, Configure
var task = target;
if ((options & ConfigureAwaitOptions.ForceYielding) != 0)
{
task = ForceYieldAsync(task);
static async Task ForceYieldAsync(Task t)
{
await Task.Yield();
await t;
}
var inner = task;
task = Task.Run(() => inner);
}
if ((options & ConfigureAwaitOptions.SuppressThrowing) != 0)
{
task = SuppressThrowAsync(task);
static async Task SuppressThrowAsync(Task t)
{
try
{
await t;
}
catch
{
}
}
task = task.ContinueWith(
static antecedent => { _ = antecedent.Exception; },
CancellationToken.None,
TaskContinuationOptions.ExecuteSynchronously,
TaskScheduler.Default);
}
return task.ConfigureAwait(
(options & ConfigureAwaitOptions.ContinueOnCapturedContext) != 0);
Expand All @@ -132,12 +122,8 @@ public static ConfiguredTaskAwaitable<TResult> ConfigureAwait<TResult>(
var task = target;
if ((options & ConfigureAwaitOptions.ForceYielding) != 0)
{
task = ForceYieldAsync(task);
static async Task<TResult> ForceYieldAsync(Task<TResult> t)
{
await Task.Yield();
return await t;
}
var inner = task;
task = Task.Run(() => inner);
}
return task.ConfigureAwait(
(options & ConfigureAwaitOptions.ContinueOnCapturedContext) != 0);
Expand Down
32 changes: 9 additions & 23 deletions src/Split/net462/Polyfill_Task.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,16 @@ public static ConfiguredTaskAwaitable ConfigureAwait(this Task target, Configure
var task = target;
if ((options & ConfigureAwaitOptions.ForceYielding) != 0)
{
task = ForceYieldAsync(task);
static async Task ForceYieldAsync(Task t)
{
await Task.Yield();
await t;
}
var inner = task;
task = Task.Run(() => inner);
}
if ((options & ConfigureAwaitOptions.SuppressThrowing) != 0)
{
task = SuppressThrowAsync(task);
static async Task SuppressThrowAsync(Task t)
{
try
{
await t;
}
catch
{
}
}
task = task.ContinueWith(
static antecedent => { _ = antecedent.Exception; },
CancellationToken.None,
TaskContinuationOptions.ExecuteSynchronously,
TaskScheduler.Default);
}
return task.ConfigureAwait(
(options & ConfigureAwaitOptions.ContinueOnCapturedContext) != 0);
Expand All @@ -132,12 +122,8 @@ public static ConfiguredTaskAwaitable<TResult> ConfigureAwait<TResult>(
var task = target;
if ((options & ConfigureAwaitOptions.ForceYielding) != 0)
{
task = ForceYieldAsync(task);
static async Task<TResult> ForceYieldAsync(Task<TResult> t)
{
await Task.Yield();
return await t;
}
var inner = task;
task = Task.Run(() => inner);
}
return task.ConfigureAwait(
(options & ConfigureAwaitOptions.ContinueOnCapturedContext) != 0);
Expand Down
32 changes: 9 additions & 23 deletions src/Split/net47/Polyfill_Task.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,16 @@ public static ConfiguredTaskAwaitable ConfigureAwait(this Task target, Configure
var task = target;
if ((options & ConfigureAwaitOptions.ForceYielding) != 0)
{
task = ForceYieldAsync(task);
static async Task ForceYieldAsync(Task t)
{
await Task.Yield();
await t;
}
var inner = task;
task = Task.Run(() => inner);
}
if ((options & ConfigureAwaitOptions.SuppressThrowing) != 0)
{
task = SuppressThrowAsync(task);
static async Task SuppressThrowAsync(Task t)
{
try
{
await t;
}
catch
{
}
}
task = task.ContinueWith(
static antecedent => { _ = antecedent.Exception; },
CancellationToken.None,
TaskContinuationOptions.ExecuteSynchronously,
TaskScheduler.Default);
}
return task.ConfigureAwait(
(options & ConfigureAwaitOptions.ContinueOnCapturedContext) != 0);
Expand All @@ -132,12 +122,8 @@ public static ConfiguredTaskAwaitable<TResult> ConfigureAwait<TResult>(
var task = target;
if ((options & ConfigureAwaitOptions.ForceYielding) != 0)
{
task = ForceYieldAsync(task);
static async Task<TResult> ForceYieldAsync(Task<TResult> t)
{
await Task.Yield();
return await t;
}
var inner = task;
task = Task.Run(() => inner);
}
return task.ConfigureAwait(
(options & ConfigureAwaitOptions.ContinueOnCapturedContext) != 0);
Expand Down
32 changes: 9 additions & 23 deletions src/Split/net471/Polyfill_Task.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,16 @@ public static ConfiguredTaskAwaitable ConfigureAwait(this Task target, Configure
var task = target;
if ((options & ConfigureAwaitOptions.ForceYielding) != 0)
{
task = ForceYieldAsync(task);
static async Task ForceYieldAsync(Task t)
{
await Task.Yield();
await t;
}
var inner = task;
task = Task.Run(() => inner);
}
if ((options & ConfigureAwaitOptions.SuppressThrowing) != 0)
{
task = SuppressThrowAsync(task);
static async Task SuppressThrowAsync(Task t)
{
try
{
await t;
}
catch
{
}
}
task = task.ContinueWith(
static antecedent => { _ = antecedent.Exception; },
CancellationToken.None,
TaskContinuationOptions.ExecuteSynchronously,
TaskScheduler.Default);
}
return task.ConfigureAwait(
(options & ConfigureAwaitOptions.ContinueOnCapturedContext) != 0);
Expand All @@ -132,12 +122,8 @@ public static ConfiguredTaskAwaitable<TResult> ConfigureAwait<TResult>(
var task = target;
if ((options & ConfigureAwaitOptions.ForceYielding) != 0)
{
task = ForceYieldAsync(task);
static async Task<TResult> ForceYieldAsync(Task<TResult> t)
{
await Task.Yield();
return await t;
}
var inner = task;
task = Task.Run(() => inner);
}
return task.ConfigureAwait(
(options & ConfigureAwaitOptions.ContinueOnCapturedContext) != 0);
Expand Down
32 changes: 9 additions & 23 deletions src/Split/net472/Polyfill_Task.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,16 @@ public static ConfiguredTaskAwaitable ConfigureAwait(this Task target, Configure
var task = target;
if ((options & ConfigureAwaitOptions.ForceYielding) != 0)
{
task = ForceYieldAsync(task);
static async Task ForceYieldAsync(Task t)
{
await Task.Yield();
await t;
}
var inner = task;
task = Task.Run(() => inner);
}
if ((options & ConfigureAwaitOptions.SuppressThrowing) != 0)
{
task = SuppressThrowAsync(task);
static async Task SuppressThrowAsync(Task t)
{
try
{
await t;
}
catch
{
}
}
task = task.ContinueWith(
static antecedent => { _ = antecedent.Exception; },
CancellationToken.None,
TaskContinuationOptions.ExecuteSynchronously,
TaskScheduler.Default);
}
return task.ConfigureAwait(
(options & ConfigureAwaitOptions.ContinueOnCapturedContext) != 0);
Expand All @@ -132,12 +122,8 @@ public static ConfiguredTaskAwaitable<TResult> ConfigureAwait<TResult>(
var task = target;
if ((options & ConfigureAwaitOptions.ForceYielding) != 0)
{
task = ForceYieldAsync(task);
static async Task<TResult> ForceYieldAsync(Task<TResult> t)
{
await Task.Yield();
return await t;
}
var inner = task;
task = Task.Run(() => inner);
}
return task.ConfigureAwait(
(options & ConfigureAwaitOptions.ContinueOnCapturedContext) != 0);
Expand Down
32 changes: 9 additions & 23 deletions src/Split/net48/Polyfill_Task.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,16 @@ public static ConfiguredTaskAwaitable ConfigureAwait(this Task target, Configure
var task = target;
if ((options & ConfigureAwaitOptions.ForceYielding) != 0)
{
task = ForceYieldAsync(task);
static async Task ForceYieldAsync(Task t)
{
await Task.Yield();
await t;
}
var inner = task;
task = Task.Run(() => inner);
}
if ((options & ConfigureAwaitOptions.SuppressThrowing) != 0)
{
task = SuppressThrowAsync(task);
static async Task SuppressThrowAsync(Task t)
{
try
{
await t;
}
catch
{
}
}
task = task.ContinueWith(
static antecedent => { _ = antecedent.Exception; },
CancellationToken.None,
TaskContinuationOptions.ExecuteSynchronously,
TaskScheduler.Default);
}
return task.ConfigureAwait(
(options & ConfigureAwaitOptions.ContinueOnCapturedContext) != 0);
Expand All @@ -132,12 +122,8 @@ public static ConfiguredTaskAwaitable<TResult> ConfigureAwait<TResult>(
var task = target;
if ((options & ConfigureAwaitOptions.ForceYielding) != 0)
{
task = ForceYieldAsync(task);
static async Task<TResult> ForceYieldAsync(Task<TResult> t)
{
await Task.Yield();
return await t;
}
var inner = task;
task = Task.Run(() => inner);
}
return task.ConfigureAwait(
(options & ConfigureAwaitOptions.ContinueOnCapturedContext) != 0);
Expand Down
32 changes: 9 additions & 23 deletions src/Split/net481/Polyfill_Task.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,16 @@ public static ConfiguredTaskAwaitable ConfigureAwait(this Task target, Configure
var task = target;
if ((options & ConfigureAwaitOptions.ForceYielding) != 0)
{
task = ForceYieldAsync(task);
static async Task ForceYieldAsync(Task t)
{
await Task.Yield();
await t;
}
var inner = task;
task = Task.Run(() => inner);
}
if ((options & ConfigureAwaitOptions.SuppressThrowing) != 0)
{
task = SuppressThrowAsync(task);
static async Task SuppressThrowAsync(Task t)
{
try
{
await t;
}
catch
{
}
}
task = task.ContinueWith(
static antecedent => { _ = antecedent.Exception; },
CancellationToken.None,
TaskContinuationOptions.ExecuteSynchronously,
TaskScheduler.Default);
}
return task.ConfigureAwait(
(options & ConfigureAwaitOptions.ContinueOnCapturedContext) != 0);
Expand All @@ -132,12 +122,8 @@ public static ConfiguredTaskAwaitable<TResult> ConfigureAwait<TResult>(
var task = target;
if ((options & ConfigureAwaitOptions.ForceYielding) != 0)
{
task = ForceYieldAsync(task);
static async Task<TResult> ForceYieldAsync(Task<TResult> t)
{
await Task.Yield();
return await t;
}
var inner = task;
task = Task.Run(() => inner);
}
return task.ConfigureAwait(
(options & ConfigureAwaitOptions.ContinueOnCapturedContext) != 0);
Expand Down
Loading
Loading