|
RPC calls can indeed be asynchronous.
I'm not sure who told you otherwise.
Synchronous messaging is just a standard way to do the baseline, just like a single threaded app is a standard baseline way to write one, but an app by definition isn't single threaded.
When you do asynchronous RPC you make the call, and you get something like a return/cancellation token you can use to retrieve your result later.
Doing RPC over HTTP can be async, you just use request/response for the request, and then request/response again for the response (or hack the http result using keep alive and spit that way)
hack everything.
|
|
|
|
|
The usual meaning of RPC is that the client blocks until the server responds. Getting back a token that is later used to retrieve the result doesn't make it look like a regular procedure call. But it's a much better way to do it.
|
|
|
|
|
yeah, it's a basic pattern in doing asynchronous programming.
Seriously, there's nothing fundamentally synchronous about RPC.
That's why it's not called SRPC.
That's why there's no ARPC
It's just RPC
Remote
Procedure
Call
Nothing in there about sychronicity
Sorry I realized afterward how much of a jerk i just sounded like.
Life stuff was frustrating me, it wasn't you.
I'm in need of a cigarette i can't have.
hack everything.
|
|
|
|
|
No need to apologize. I don't think you sounded like a jerk.
|
|
|
|
|
I'm glad to hear it, because I was frustrated when I wrote it, and I can tell by reading it, but I wasn't frustrated at you. =)
One of the nice things about JS is it's really easy to set it up to do asynchronous RPC. Creating a "thread" in javascript (not a real thread) is easy as pie, and since it's not a real thread, but rather a cooperatively scheduled fiber spawned by the browser you don't need to work synchronization primitives.
Basically the browser is creating your state machine for you if you just <script> to an url (or any of the other enumerable ways to get JS to load something asynchronously)
Adding: with JS you wouldn't use a cancelation token, but rather a callback method ala JSONP to do your async notify. In JS this is cake as all functions are basically delegate objects
hack everything.
|
|
|
|
|
I route responses to asynchronous requests just like other messages: received by an I/O thread, put on a work queue, and eventually dequeued by an "invoker thread", so named because it invokes applications to pass them messages. I find that there are advantages to having a consistent flow of control.
|
|
|
|
|
I mean, this is basically what that cooperative fiber stuff is doing behind the scenes. It's got a message pump. It's just that JS, being a scripting language, does it for you and hides the grotty details.
The upshot is you don't have script kids blowing up multithreaded code.
The downside is you don't have any more control than what you can convince JS to give you.
But overall, it's a good model considering the audience. Makes async painless, and it's actually almost easier to do async than sync calls with JS.
hack everything.
|
|
|
|
|
If it's easier to do asynch than synch, it definitely has my vote of approval!
|
|
|
|
|
It's weird how to do it, but yes, in at least half the cases it's easier to do async than sync
Javascript is a strange animal, especially when using it this way and "threading" using the browser's dom elements like script blocks. It's a total hackfest, like most of javascript, but once you get the model down, if you abstract it then using it is lovely.
hack everything.
|
|
|
|
|
My boss keeps talking about Python having "support" for JSON as well.
But I don't need "support" (and I don't touch Javascript (ptui)).
I definitely do not need to have a million "objects" all in memory at once.
All I do is kinda stream it into SQL Server as quickly as I can.
Edit:
Plus, I can't simply go downloading stuff and installing it, and it would likely take at least a year for the "security" weenies to approve a package.
So, I roll my own. Now I have an importer utility which can read XML, JSON, or "CSV" -- convert to XML as necessary -- and write to SQL Server in a number of ways.
modified 9-Jan-20 19:03pm.
|
|
|
|
|
that works.
Your boss is silly. Pretty much every turing complete language has "JSON support" but Javascript is the only one where JSON objects are truly "first class" objects and not behind a facade.
hack everything.
|
|
|
|
|
honey the codewitch wrote: are truly "first class" objects
Which I don't need. At all.
|
|
|
|
|
it's nice when you're trying to RPC from inside a browser though!
hack everything.
|
|
|
|
|
I write backend database stuff.
At times calling RESTfull services and such to get data and load it into staging. Being able to consume JSON is very helpful.
|
|
|
|
|
Hmm, so there's nothing stopping me from implementing a JSON parser in XSLT...
|
|
|
|
|
I'm not sure how you'd lex in XSLT, to be honest.
Besides, it's easier to write one in Parsley:
Json<start>= Object | Array;
Object= "{" [ Field { "," Field } ] "}";
Field= string ":" Value;
Array= "[" [ Value { "," Value } ] "]";
Value<collapsed>=
string |
number |
Object |
Array |
Boolean |
null ;
Boolean= true|false;
number= '\-?(0|[1-9][0-9]*)(\.[0-9]+)?([Ee][\+\-]?[0-9]+)?';
string= '"([^\n"\\]|\\([btrnf"\\/]|(u[0-9A-Fa-f]{4})))*"';
true= "true";
false= "false";
null= "null";
lbracket<collapsed>= "[";
rbracket<collapsed>= "]";
lbrace<collapsed>= "{";
rbrace<collapsed>= "}";
colon<collapsed>= ":";
comma<collapsed>= ",";
whitespace<hidden>= '[\n\r\t ]+';
but then I'm biased i guess.
hack everything.
|
|
|
|
|
When I first saw JSON, I cried. The beauty of well defined XML, the ability to verify the XML with a schema, the ability to extend the XML, the ability to have semantic meaning...all down the drain. Probably created by the same idiots people that created duck-typed languages like Ruby.
That said, I do like JSON now, certainly as a terser way of representing simple data structures. But yeah, once you get into more complex structures, the serialization / deserialization, the null handling, the complexity of instantiating a specific type derived from an abstract type...it all becomes a PITA.
So, I feel your pain.
|
|
|
|
|
Not sure why you'd be using a .NET 1-era collection instead of a Dictionary<string, string> ; but it's fairly simple to fix the issue with a custom JSON converter:
public class StringDictionaryConverter : JsonConverter
{
public override bool CanRead => true;
public override bool CanWrite => true;
public override bool CanConvert(Type objectType) => typeof(StringDictionary).IsAssignableFrom(objectType);
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var dictionary = (StringDictionary)value;
writer.WriteStartObject();
foreach (DictionaryEntry entry in dictionary)
{
writer.WritePropertyName((string)entry.Key);
writer.WriteValue(entry.Value);
}
writer.WriteEndObject();
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null) return null;
var dictionary = existingValue as StringDictionary ?? (StringDictionary)serializer.ContractResolver.ResolveContract(objectType).DefaultCreator();
switch (reader.TokenType)
{
case JsonToken.StartObject:
{
var values = serializer.Deserialize<Dictionary<string, string>>(reader);
foreach (var pair in values)
{
dictionary.Add(pair.Key, pair.Value);
}
break;
}
case JsonToken.StartArray:
{
var values = serializer.Deserialize<List<KeyValuePair<string, string>>>(reader);
foreach (var pair in values)
{
dictionary.Add(pair.Key, pair.Value);
}
break;
}
default:
{
throw new JsonSerializationException($"Unknown token {reader.TokenType} at path {reader.Path}");
}
}
return dictionary;
}
} Example:
var source = new StringDictionary
{
["xml"] = "sucks",
["json"] = "rules",
};
string json = JsonConvert.SerializeObject(source, new StringDictionaryConverter());
var result = JsonConvert.DeserializeObject<StringDictionary>(json, new StringDictionaryConverter()); (Based on [Fork] [Fork] questions/52721999/modelstate-error-newtonsoft-json-jsonserializationexception-cannot-populate-l?noredirect=1#comment92399021_52721999 | C# Online Compiler | .NET Fiddle[^])
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Is a man who wears a loincloth and lives on top of a Christmas cake called Tarzipan?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Would that make Jane a Jelly Babe?
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
As long as it is not one of the Urban Dictionary definitions, then I am fine with being a British sweet.
|
|
|
|
|
No, it's not an Urban Dictionary reference, and yes, I did mean the sweet.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
It must have taken a lot of Mozart Kugeln to write that.
|
|
|
|
|
"man in a loincloth onna cake" ??? not a pretty picture (even Dibbler wouldn't go that low)
kid safe (??) examples -> https://www.cakewrecks.com/home/2013/3/13/ken-day-come-ons.html[^]
.... is the last one what you're suggesting?
after many otherwise intelligent sounding suggestions that achieved nothing the nice folks at Technet said the only solution was to low level format my hard disk then reinstall my signature. Sadly, this still didn't fix the issue!
|
|
|
|
|
Reminds me, I have Xmas Stollen to eat.
I love Marzipan, my wife hates it. Marzipan cake in Norway. Yum.
|
|
|
|