Comments (5)
it's working in this version! Thank you!😊
public interface ITripMonitor : IComputeService
{
Task<int> AddOrUpdate(int tripId, CancellationToken cancellationToken = default);
Task Remove(int tripId, CancellationToken cancellationToken = default);
[ComputeMethod]
Task<List<int>> List(CancellationToken cancellationToken = default);
[ComputeMethod]
Task<int> Count(CancellationToken cancellationToken = default);
}
public class TripMonitor : ITripMonitor
{
private ImmutableList<int> _tripruning = ImmutableList<int>.Empty;
private readonly IMutableState<int> _count;
public TripMonitor(IStateFactory stateFactory)
=> _count = stateFactory.NewMutable<int>(0);
public virtual async Task<int> AddOrUpdate(int tripId, CancellationToken cancellationToken = default)
{
_tripruning = _tripruning.RemoveAll(i => i == tripId).Add(tripId);
_count.Value +=1;
using var invalidating = Computed.Invalidate();
await List();
return tripId;
}
public virtual async Task Remove(int tripId, CancellationToken cancellationToken = default)
{
_tripruning = _tripruning.RemoveAll(i => i == tripId);
_count.Value -= 1;
using var invalidating = Computed.Invalidate();
await List();
}
public virtual Task<List<int>> List(CancellationToken cancellationToken = default)
{
return Task.FromResult(_tripruning.ToList());
}
public virtual async Task<int> Count(CancellationToken cancellationToken = default)
{
return await _count.Use(cancellationToken);
}
}
from stl.fusion.
Hi, AddOrRemove and Update in your code don't have a logic that invalidates List.
Computed.Invalidate() call doesn't do anything alone - it just opens a scope that forces every call to [ComputeMethod] made from this scope into invalidating call (of a method you call - with the args you pass).
So all you need is to add List() call to the end of both of these methods.
You also don't need if (Computed.IsInvalidating()) piece inside regular methods. The logic that runs the same method twice, where the second "pass" is running inside invalidating block, is applicable only for command handlers.
Hopefully this helps. Free to ask more questions :)
from stl.fusion.
One other change I recommend to do: move "use invalidating = ..." to the very end. You should run invalidation logic once the changes are already applied, but never earlier, coz otherwise you leave a chance for evaluation of whatever is invalidated before the change is actually made, which makes invalidation to produce zero effect.
from stl.fusion.
Thank you very much for your reply.
I have already removed the Invalidate(), but the problem still persists. Could you please advise on how I should modify it.
public interface ITripMonitor : IComputeService
{
Task<int> AddOrUpdate(int tripId, CancellationToken cancellationToken = default);
Task Remove(int tripId, CancellationToken cancellationToken = default);
[ComputeMethod]
Task<List<int>> List(CancellationToken cancellationToken = default);
[ComputeMethod]
Task<int> Count(CancellationToken cancellationToken = default);
}
public class TripMonitor : ITripMonitor
{
private ImmutableList<int> _tripruning = ImmutableList<int>.Empty;
private readonly IMutableState<int> _count;
public TripMonitor(IStateFactory stateFactory)
=> _count = stateFactory.NewMutable<int>(0);
public virtual Task<int> AddOrUpdate(int tripId, CancellationToken cancellationToken = default)
{
_tripruning = _tripruning.RemoveAll(i => i == tripId).Add(tripId);
_count.Value +=1;
_ = List();
return Task.FromResult(tripId);
}
public virtual async Task Remove(int tripId, CancellationToken cancellationToken = default)
{
_tripruning = _tripruning.RemoveAll(i => i == tripId);
_count.Value -= 1;
_ = List();
}
public virtual Task<List<int>> List(CancellationToken cancellationToken = default)
{
return Task.FromResult(_tripruning.ToList());
}
public virtual async Task<int> Count(CancellationToken cancellationToken = default)
{
return await _count.Use(cancellationToken);
}
}
from stl.fusion.
Ok, I guess you can close the issue now :)
from stl.fusion.
Related Issues (20)
- Replace LogLevel / XxxLogLevel with IsLoggingEnabled everywhere
- Possible renames HOT 2
- Add System.Text.Json serializer support HOT 1
- Add MessagePack serializer support HOT 4
- Sign the assemblies that could be signed
- async alternate HOT 3
- [StateHasChangedAsync] System.NullReferenceException: 'Object reference not set to an instance of an object.' HOT 8
- infinite query loop HOT 7
- blazor wasm only (no server side blazor) can't get auth schemes HOT 3
- Exception when using together with Moq 4.18.1 HOT 9
- Don't mask HTTP errors in replica services HOT 1
- Improve test coverage
- A DateTime value was incorrectly passed to the server in Korean. HOT 2
- Commands are executed twice? HOT 3
- Could not load type 'Stl.Fusion.Bridge.IChannelProvider' from assembly 'Stl.Fusion
- Live sample at https://fusion-samples.servicetitan.com/ is broken in wasm mode HOT 2
- Assistance/Improvement for Factories/Proxies using ActivatorUtilities HOT 7
- Stl.Interception gets trimmed away HOT 10
- Add Stl.Async-way of awaiting WaitHandle HOT 3
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 stl.fusion.