Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancellation tokens and propagation #3893

Merged
merged 1 commit into from
May 8, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class TestConfigurationRetriever : IConfigurationRetriever<IDictionary<st
{
public IDictionary<string, HashSet<string>> EndorsementTable { get; } = new Dictionary<string, HashSet<string>>();

public Task<IDictionary<string, HashSet<string>>> GetConfigurationAsync(string address, IDocumentRetriever retriever, CancellationToken cancel)
public Task<IDictionary<string, HashSet<string>>> GetConfigurationAsync(string address, IDocumentRetriever retriever, CancellationToken cancellationToken)
{
return Task.FromResult(EndorsementTable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public abstract class InputDialog : Dialog
dc.State.SetValue(property, null);
}

var state = alwaysPrompt ? InputState.Missing : await this.RecognizeInputAsync(dc, 0).ConfigureAwait(false);
var state = alwaysPrompt ? InputState.Missing : await this.RecognizeInputAsync(dc, 0, cancellationToken).ConfigureAwait(false);
if (state == InputState.Valid)
{
var input = dc.State.GetValue<object>(VALUE_PROPERTY);
Expand All @@ -193,7 +193,7 @@ public abstract class InputDialog : Dialog
// We will set the turn count to 1 so the input will not pick from "dialog.value"
// and instead go with "turn.activity.text"
dc.State.SetValue(TURN_COUNT_PROPERTY, 1);
return await this.PromptUserAsync(dc, state).ConfigureAwait(false);
return await this.PromptUserAsync(dc, state, cancellationToken).ConfigureAwait(false);
}
}

Expand All @@ -209,7 +209,7 @@ public abstract class InputDialog : Dialog
var turnCount = dc.State.GetValue<int>(TURN_COUNT_PROPERTY, () => 0);

// Perform base recognition
var state = await this.RecognizeInputAsync(dc, interrupted ? 0 : turnCount).ConfigureAwait(false);
var state = await this.RecognizeInputAsync(dc, interrupted ? 0 : turnCount, cancellationToken).ConfigureAwait(false);

if (state == InputState.Valid)
{
Expand All @@ -221,13 +221,13 @@ public abstract class InputDialog : Dialog
dc.State.SetValue(this.Property.GetValue(dc.State), input);
}

return await dc.EndDialogAsync(input).ConfigureAwait(false);
return await dc.EndDialogAsync(input, cancellationToken: cancellationToken).ConfigureAwait(false);
}
else if (this.MaxTurnCount == null || turnCount < this.MaxTurnCount.GetValue(dc.State))
{
// increase the turnCount as last step
dc.State.SetValue(TURN_COUNT_PROPERTY, turnCount + 1);
return await this.PromptUserAsync(dc, state).ConfigureAwait(false);
return await this.PromptUserAsync(dc, state, cancellationToken).ConfigureAwait(false);
}
else
{
Expand All @@ -236,7 +236,7 @@ public abstract class InputDialog : Dialog
var (value, error) = this.DefaultValue.TryGetValue(dc.State);
if (this.DefaultValueResponse != null)
{
var response = await this.DefaultValueResponse.BindAsync(dc).ConfigureAwait(false);
var response = await this.DefaultValueResponse.BindAsync(dc, cancellationToken).ConfigureAwait(false);

var properties = new Dictionary<string, string>()
{
Expand All @@ -245,13 +245,13 @@ public abstract class InputDialog : Dialog
};
TelemetryClient.TrackEvent("GeneratorResult", properties);

await dc.Context.SendActivityAsync(response).ConfigureAwait(false);
await dc.Context.SendActivityAsync(response, cancellationToken).ConfigureAwait(false);
}

// set output property
dc.State.SetValue(this.Property.GetValue(dc.State), value);

return await dc.EndDialogAsync(value).ConfigureAwait(false);
return await dc.EndDialogAsync(value, cancellationToken).ConfigureAwait(false);
}
}

Expand All @@ -260,7 +260,7 @@ public abstract class InputDialog : Dialog

public override async Task<DialogTurnResult> ResumeDialogAsync(DialogContext dc, DialogReason reason, object result = null, CancellationToken cancellationToken = default(CancellationToken))
{
return await this.PromptUserAsync(dc, InputState.Missing).ConfigureAwait(false);
return await this.PromptUserAsync(dc, InputState.Missing, cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public class OAuthInput : InputDialog
{
// increase the turnCount as last step
dc.State.SetValue(TURN_COUNT_PROPERTY, turnCount + 1);
var prompt = await this.OnRenderPromptAsync(dc, inputState).ConfigureAwait(false);
var prompt = await this.OnRenderPromptAsync(dc, inputState, cancellationToken).ConfigureAwait(false);
await dc.Context.SendActivityAsync(prompt).ConfigureAwait(false);
await SendOAuthCardAsync(dc, promptOptions?.Prompt, cancellationToken).ConfigureAwait(false);
return Dialog.EndOfTurn;
Expand All @@ -238,23 +238,23 @@ public class OAuthInput : InputDialog
var (value, _) = this.DefaultValue.TryGetValue(dc.State);
if (this.DefaultValueResponse != null)
{
var response = await this.DefaultValueResponse.BindAsync(dc).ConfigureAwait(false);
var response = await this.DefaultValueResponse.BindAsync(dc, cancellationToken).ConfigureAwait(false);
var properties = new Dictionary<string, string>()
{
{ "template", JsonConvert.SerializeObject(this.DefaultValueResponse) },
{ "result", response == null ? string.Empty : JsonConvert.SerializeObject(response, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }) },
};
TelemetryClient.TrackEvent("GeneratorResult", properties);
await dc.Context.SendActivityAsync(response).ConfigureAwait(false);
await dc.Context.SendActivityAsync(response, cancellationToken).ConfigureAwait(false);
}

// set output property
dc.State.SetValue(this.Property.GetValue(dc.State), value);
return await dc.EndDialogAsync(value).ConfigureAwait(false);
return await dc.EndDialogAsync(value, cancellationToken).ConfigureAwait(false);
}
}

return await dc.EndDialogAsync().ConfigureAwait(false);
return await dc.EndDialogAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public override void Initialize(IEnumerable<OnCondition> conditionals, bool eval
_evaluate = evaluate;
}

public override async Task<IReadOnlyList<OnCondition>> SelectAsync(ActionContext actionContext, CancellationToken cancel = default)
public override async Task<IReadOnlyList<OnCondition>> SelectAsync(ActionContext actionContext, CancellationToken cancellationToken = default)
{
var (eval, _) = Condition.TryGetValue(actionContext.State);
TriggerSelector selector;
Expand All @@ -70,7 +70,7 @@ public override async Task<IReadOnlyList<OnCondition>> SelectAsync(ActionContext
IfFalse.Initialize(_conditionals, _evaluate);
}

return await selector.SelectAsync(actionContext, cancel).ConfigureAwait(false);
return await selector.SelectAsync(actionContext, cancellationToken).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override void Initialize(IEnumerable<OnCondition> conditionals, bool eval
_evaluate = evaluate;
}

public override Task<IReadOnlyList<OnCondition>> SelectAsync(ActionContext context, CancellationToken cancel)
public override Task<IReadOnlyList<OnCondition>> SelectAsync(ActionContext context, CancellationToken cancellationToken)
{
OnCondition selection = null;
var lowestPriority = int.MaxValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public override void Initialize(IEnumerable<OnCondition> conditionals, bool eval
}
}

public override async Task<IReadOnlyList<OnCondition>> SelectAsync(ActionContext context, CancellationToken cancel)
public override async Task<IReadOnlyList<OnCondition>> SelectAsync(ActionContext context, CancellationToken cancellationToken)
{
var triggers = _tree.Matches(context.State);
var matches = new List<OnCondition>();
Expand All @@ -50,7 +50,7 @@ public override async Task<IReadOnlyList<OnCondition>> SelectAsync(ActionContext
if (Selector != null)
{
Selector.Initialize(matches, false);
selections = await Selector.SelectAsync(context, cancel).ConfigureAwait(false);
selections = await Selector.SelectAsync(context, cancellationToken).ConfigureAwait(false);
}

return selections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public override void Initialize(IEnumerable<OnCondition> conditionals, bool eval
}
}

public override Task<IReadOnlyList<OnCondition>> SelectAsync(ActionContext context, CancellationToken cancel = default)
public override Task<IReadOnlyList<OnCondition>> SelectAsync(ActionContext context, CancellationToken cancellationToken = default)
{
var candidates = _conditionals;
if (_evaluate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override void Initialize(IEnumerable<OnCondition> conditionals, bool eval
_evaluate = evaluate;
}

public override Task<IReadOnlyList<OnCondition>> SelectAsync(ActionContext context, CancellationToken cancel = default)
public override Task<IReadOnlyList<OnCondition>> SelectAsync(ActionContext context, CancellationToken cancellationToken = default)
{
var candidates = _conditionals;
if (_evaluate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ public T LoadType<T>(Resource resource)
/// </summary>
/// <typeparam name="T">type to create.</typeparam>
/// <param name="resource">resource to bind to.</param>
/// <param name="cancellationToken">the <see cref="CancellationToken"/> for the task.</param>
/// <returns>task which will resolve to created type.</returns>
public async Task<T> LoadTypeAsync<T>(Resource resource)
public async Task<T> LoadTypeAsync<T>(Resource resource, CancellationToken cancellationToken = default)
{
RegisterComponentTypes();

Expand All @@ -165,7 +166,7 @@ public async Task<T> LoadTypeAsync<T>(Resource resource)
try
{
var sourceContext = new SourceContext();
var (json, range) = await ReadTokenRangeAsync(resource, sourceContext).ConfigureAwait(false);
var (json, range) = await ReadTokenRangeAsync(resource, sourceContext, cancellationToken).ConfigureAwait(false);
using (new SourceScope(sourceContext, range))
{
var result = Load<T>(json, sourceContext);
Expand Down