Does asynchronous code in neovim-Lua work the same as in Javascript? - asynchronous

Is asynchronous code in neovim-Lua the same as it is in JS?
Hello everybody.
I have been taking a look at IO in Lua recently and I see there are some asynchronous APIS there. I am an experienced JS developer, so I'm more than familiar with asynchronous programming and the event loop. However, by reading the Lua docs, neovim docs and the plenary docs is still not clear to me how the asynchronous code works exactly in Lua. In Javascript, everything that is asynchronous is because depends on some external resource, and while it waits for that resource to answer the rest of the events can be processed. But I'm not sure if it is like this in Lua, and particularly in the neovim methods for reading documents or calling external commands. The code snippets I saw make use of Lua coroutines and they give me the impression that the code behaves like normal synchronous code: when you try to consume a coroutines the calling code seems to wait for it, so I'm not sure what is the point if it is like that. Am I wrong and it works exactly like in Javascript? If I call an external command from neovim the editor will not block while it is being executed despite my code looks like regular synchronous code?
Thanks all

Related

Fastapi asynchronous response (bg tasks)

I am using fastapi for the first time in a project.
I receive information from an html form and return a HTMLResponse object to indicate that the program is running in the background (thanks to the BackgroundTask object). Is there a way to return another HTML file and to make my browser switch to that once the background task is over?
Sorry if I use the wrong terminology, but I am no expert.
Cheers
So what you need to do here is implement websockets. After your task is finished you can have to send a message on the websockets intimidating that the task has finished.
Think of it like a notification service.
You can find some documentation here
You will have to connect to the websocket from your frontend as well.
Do you research on this, I'm sure you will find a lot of documentation and articles on this idea.

when to use Synchronous and Asynchronous Request?

can any one explain. when to use Synchronous and Asynchronous request with example.enter code here
Generally speaking, asynchronous requests do not block the running environment until they get a response. This keeps your UI responsive while waiting for the response, and enables your user to use it. With synchronous requests, the UI would feel like it would be frozen.
I would say that while developing a web application, you would probably use asynchronous requests 99.9% of time.
From a software engineering stand of point, synchronous code is using one process, while asynchronous code executes a concurrent process. That is exactly how your UI is enabled to be responsive. It's like as if the asynchronous code ran as another program, if you will.

node.js asynchronous initialization issue

I am creating a node.js module which communicates with a program through XML-RPC. The API for this program changed recently after a certain version. For this reason, when a client is created (createClient) I want to ask the program its version (through XML-RPC) and base my API definitions on that.
The problem with this is that, because I do the above asynchronously, there exists a possibility that the work has not finished before the client is actually used. In other words:
var client = program.createClient();
client.doSomething();
doSomething() will fail because the API definitions have not been set, I imagine because HTTP XML-RPC response has not returned from the program.
What are some ways to remedy this? I want to be able to have a variable named client and work with that, as later I will be calling methods on it to get information (which will be returned via a callback).
Set it up this way:
program.createClient(function (client) {
client.doSomething()
})
Any time there is IO, it must be async. Another approach to this would be with a promise/future/coroutine type thing, but imo, just learning to love the callback is best :)

Asp.net Asynchronous programming model and Ajax

I am a bit confused here with the way in which asynchronous programming can be done.
As I think, I can always use AJAX for the same.
I am a bit confused here with the way in which asynchronous programming can be done.
I would recommend you the following article on MSDN if you want to do real asynchronous programming on the server. AJAX concerns only the client side part (javascript). You could still have perfectly synchronous server code but by using AJAX you are faking from the client perspective an asynchronous call so that his browser stays responsive and is able to perform other tasks on the page during the AJAX call.
Yes, AJAX is used most of time and it will handle Asynchronous request, but you can use jquery as well for your Asynchrous operation as well.

ASP.net server event handled client-side

I was wondering if anyone had an easy way to wire up javascript event handlers to events happening on the server-side. I have a long running process that includes a lot of steps, and would like the client to be continually updated with new information as the steps transition. Will this involve some sort of polling mechanism?
Send an AJAX or JSON request from the client every so often asking for status.xml. Then, on the server, when something changes, just quickly write a new line to status.xml the same way you would to the console. You can use setInterval( function, timeBetweenRuns ) in Javascript to do this regularly.
would it be possible to use an update panel to do this with maybe a timer? it's sort of how I would do it.
Course, this depends on what you're doing already. I'm assuming you're using Forms...
Ajax calling a Web Service is how I would do it.

Resources