Async javascript function block

Make JS function blocks Async by default or add a special async JS function block for performing things such as http requests or timers.

Not by default; the kinds of JS blocks people have invented mostly don't need it. And the one case I know about that did need it (the bignum library) set up an async thread (loading a JS library from the web) inside its own code. But I can see it as an option.

Ye.. shouldn't be something too difficult to implement. I mostly need it because I am doing a lot of HTTP requests, using sockets, timers, etc and don't know how to halt/pause until a response is recieved without polling the object as await is unavailable

Look in the "infinite precision integers..." library, and edit the USE BIGNUMS block (in Operators). It loads code from the net and sets up a callback. Beyond my own expertise, but you'll understand it, and maybe it'll help you.

Ok, will do when I can. Would still be a valuable edition though in the cases where it would be required.

You don't need async for JS, because Snap! is multi-threaded.

I meant just for JS functions
i.e.

async function post(url, data) {
return await request("POST", url, data, headersFrom(data));
}

Hi @wunder_wulfe,

I think you can do what you want.

You need to yield that reporter and then, it will return to that process thread again until your callback ends. To do it easily, you can check "Web services access" library. Check "GET url..." block. It is a simple example to show that you can reference its own "process", and you can yield without return until the async function ends.

Joan

Is there any way by function to yield the block manually without using something like wait until and calling a function every tick?