Comments (4)
You can workaround this by using an EnsureInitializeAsync
pattern. InitializeState
will kick off the task to populate the state, and then each operation will await
that task.
private readonly Task? _initialization;
public async Task MyOperation()
{
await EnsureInitializedAsync();
}
protected T InitializeState(..)
{
async InitializeAsync()
{
// async work
}
_initialization = InitializeAsync();
return default(T); // InitializeAsync
}
private Task InitializeAsync()
{
// perform async work
this.State = T; // set this.State
}
private ValueTask EnsureInitializedAsync()
{
return _initialization is null ? default : new(_initialization);
}
from durabletask-dotnet.
Yes, returning default(T)
would be fine there. InitializeState
is just a convenience method for populating state when there is none. I updated my sample to show that.
You could also set it in InitializeState
and then populate its contents in InitializeAsync
.
from durabletask-dotnet.
Thread is also blocked in my initializeState because async operations are not supported
from durabletask-dotnet.
Thanks @jviau. Would this pattern still work with this method signature?
protected override T InitializeState(TaskEntityOperation operation){}
as I need to return T
not void (as the entity inherites from TaskEntity<T>
) and it looks like the base class will store the returned value in the base.State
property.
Full Code Example
public class T : TaskEntity<T>
{
public void MyMethod() { }
[Function(nameof(T))]
public static Task RunEntityAsync([EntityTrigger] TaskEntityDispatcher dispatcher)
{
return dispatcher.DispatchAsync<T>();
}
protected override T InitializeState(TaskEntityOperation operation)
{
//inject EnsureInitializeAsync pattern here?
T state = new();
return state;
}
}
Also worth noting, an additional alternative would be to use the functions based syntax which would allow the populating of the state inside the DispatchAsync()
from durabletask-dotnet.
Related Issues (20)
- Unit Testing Isolated Model Azure Durable Function Orchestrator in .Net 8 HOT 6
- PurgeInstancesAsync fails after 100 seconds
- Class syntax example doesn't work HOT 2
- PurgeAllInstancesAsync Fails with Exception when there are no instances to Purge from PurgeFilter HOT 1
- Listing instances with DurableTaskClient.GetAllInstancesAsync() is more than twice as slower than with IDurableOrchestrationClient.ListInstancesAsync() HOT 4
- Durable functions hubname cannot be configured from app settings HOT 1
- WaitForExternalEvent<T>(eventName, timespan, cancellationToken) not supported (anymore?) in isolated mode
- Ability to Set Both RetryPolicy? Policy and AsyncRetryHandler? Handler in TaskRetryOptions HOT 8
- (De)serialize `State` property when using `TaskEntity<TState>`-based implementation not working (correctly) HOT 7
- DurableTaskClient.PurgeAllInstancesAsync: NotSupportedException and RpcException for .net 8 isolated HOT 11
- Roslyn Analyzer: System.TimeProvider
- Roslyn Analyzer: document how orchestrations are analyzed and the method probing is executed.
- The filter passed to _PurgeAllInstancesAsync(PurgeInstancesFilter filter, CancellationToken cancellation)_ on the DurableTaskClient, is not used, instead a new instance is created HOT 1
- Any documentation on how to build the project? HOT 1
- RaiseEventAsync with a given taskhubname is missing compared to in process HOT 4
- Investigate state sharing between different Roslyn analyzers
- RpcException - PurgeAllInstancesAsync operation was canceled - HttpClient.Timeout of 100 seconds elapsing HOT 4
- Improve environment variable analyzer to catch dotnet configuration APIs
- Keep getting "Error connecting to subchannel." errors when running on Azure HOT 1
- EntityTrigger does not get triggered in version of Microsoft.Azure.Functions.Worker.Extensions.DurableTask 1.1.3 HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from durabletask-dotnet.