[FunctionName("SetDurable")]
public static async Task<HttpResponseMessage> SetDurable(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "SetDurable/{durable}")] HttpRequestMessage req,
[DurableClient] IDurableEntityClient client,
string durable)
{
var entityId = new EntityId(DurableEntitiesNames.BirSessionIdentificatorEntity, DurableEntitiesNames.BirSessionIdentificatorKey);
await client.SignalEntityAsync<IBirSessionIdentificator>(entityId, identificator => identificator.Set(durable) );
//await Task.Delay(2000);
EntityStateResponse<JObject> stateResponse = await client.ReadEntityStateAsync<JObject>(entityId);
var setResult = stateResponse.EntityState.ToObject<BirSessionIdentificatorResult>().Sid;
return new HttpResponseMessage(HttpStatusCode.OK){Content = new StringContent($"{setResult}")};
}
In Azure Functions v3 when i try to set the value of durable entity and then immediately try to read this value, it returns old value instead of the new value. But when i uncomment the Task.Delay and make it wait 2 seconds after setting the value of durable entity i get correct value while trying to read it.
Is there any way to await the completion of durable entity value setting operation?
No, at least not when using
SignalEntityAsync
. See the docs:The bold part is your way out: you can use a proxy from within an orchestration to get access to the durable entity. That way you can await the operation. An example:
here we await the call of the Delete method on the entity.