Comments (5)
Hi Felix,
This is a great question. I have in fact pondered how to approach this a few times since we first implemented it in CI. Back then, .NET 3.5 support was still on the cards (it's not any longer) so we thought about how we could expose this functionality without leaking things like Task into the interface. At the time we also weren't sure about things like support for TPL in Mono, and we didn't want to annoy the mono users by adding something that they couldn't use.
We decided to go with the callback option so that the users could decide what they wanted to do with marshalling the result back onto the appropriate thread. This meant that the mechanism used for managing the task on a separate thread was hidden and if we needed to change it across implementations then the interface could stay the same.
The negative to this approach is that there is no nice/obvious way of doing that as a caller.
Given that 3.5 support is off the cards and that everyone is on at least 4.0 if not 4.5 already, I think it's time that we review this functionality and provide something that is a little nicer.
At this point my view is that we change the client interface such that the Async.* operations no longer follow the pattern of void SyncFunctionName(T1 arg1, T2 arg2, ..., Action<TSyncFunctionReturnType> callback);
. This was put in place to make the Async interface intuitive. we just pushed the return value through to the action on a separate thread. Instead of following this pattern, the Async interface should have the same signature as the Sync version, except that any return values are wrapped in a Task.
To use your example of using RiakResult<RiakObject> Get(string bucket, string key)
, the Async version becomes Task<RiakResult<RiakObject>> Get(string bucket, string key)
which then allows the caller to reference the Result
property on the return value. Hence we go from this:
RiakResult<RiakObject> result = Client.Get(someBucket, someKey);
To this
RiakResult<RiakObject> result = Client.Async.Get(someBucket, someKey).Result;
This also gives us the added benefit of being able to use the other nice stuff that comes with TPL, such as ContinueWith<T>()
.
What do you think? I think it'd solve the problem, but the question is: is this what people are going to want to work with?
While we discuss this option I'll ponder some documentation which demonstrates how you can do the marshalling with the current interface.
Thanks Felix!
OJ
from riak-dotnet-client.
Hi OJ,
Actually, that sounds perfect. Allowing the use of TPL makes dealing with these results a straightforward proposition. And it seems to adhere to best practices a la http://msdn.microsoft.com/en-us/vstudio/hh533273.aspx (the section near the bottom which talks about ContinueWith, and Wait, rang a bell here).
Also, following such a call style for Async vs Sync is going to look very similar in terms of textual formatting. This should make documentation easier to read in the long run, and I think that users will find the whole thing easier to grasp.
Thanks and best regards,
Felix
from riak-dotnet-client.
Hi Felix,
I've made the changes that I said I was going to make and have pushed them into the develop branch (see changeset above). Hopefully you'll find this useful. Please feel free to take a look at the changes and let me know if you think they'll be appropriate.
The old callback style interface is still in there but has been marked as obsolete, so you should see a compiler warning when you rebuild.
We're pushing to get this stuff released very soon along with some other changes that people have been waiting for, so bear with us while we finish up the 1.0 release.
If you're happy that these changes are ok, would you mind closing the issue?
Cheers!
OJ
from riak-dotnet-client.
Hi OJ,
Thanks a lot for making these changes!
-f
from riak-dotnet-client.
No problem Felix. I hope that this will make it easier for you to achieve your goals. Please keep us posted on how it all goes.
Expect to see a release appear in Nuget very soon.
Cheers!
from riak-dotnet-client.
Related Issues (20)
- Issue with health check / node selection HOT 2
- No results found yields IsSuccess == false HOT 1
- Compiling under Mono breaks stuff HOT 1
- Default value for deletedvclock
- RiakClient.Delete Bug HOT 5
- Riak TS support
- Nodes are not marked Offline for a failed GET request HOT 10
- Riak client does not support the use of a load balancer HOT 14
- The "externalLoadBalancer" doesn't take multiple-load balancer scenarios into account HOT 2
- RiakClient.Delete issue [JIRA: CLIENTS-898] HOT 3
- Don't lose original error when returning "ClusterOffline"
- Update riak_pb submodule when tagged
- Optional fields with default values in PB messages
- Upon save/update failure - no way to get Id
- Target .NET Standard
- Revamp publish process
- Riak TS - when rpberrorresp is returned, text is unavailable HOT 1
- Fluent connection configuration ? HOT 2
- System.configuration could not be resolved HOT 1
- Add warning and safety mechanism to prevent unintentional list [buckets | keys] operations
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 riak-dotnet-client.