eupolicy.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
This Mastodon server is a friendly and respectful discussion space for people working in areas related to EU policy. When you request to create an account, please tell us something about you.

Server stats:

196
active users

#async

1 post1 participant0 posts today

What if your PHP functions could pause, resume, and remember where they left off, like little self-aware scripts? ⏯️

That’s what coroutines are for, and PHP gives you two tools to use them: Generators (since 5.5) and Fibers (in PHP 8.1).

🥔 🔥 I break it all down with real code, plus a hot potato metaphor you won’t forget:
doeken.org/blog/coroutines-in-

doeken.org · Exploring Coroutines in PHPCoroutines are functions that pause and resume with state, allowing flexible, bidirectional control flow in PHP.

How I normally do #async external programs in my #commonLisp image #embeddableCommonLisp and #uiop (in the notes).

screwlisp.small-web.org/progra

Originally I was writing Kittenette (Closette but for kittens) today, but I ended up wanting to individually treat external processes, especially from #ecl on its own first.

My example is particularly using #cat(1) as an external-process in-memory echo server.

Hope it helps someone. #programming #example

Yes "multi-processing" in the url is ~erroneous.

screwlisp.small-web.orgEmbeddable Common Lisp External Program Asyncronously
Continued thread

Solved! 🥳

This was a pretty "interesting" bug. Remember when I invented a way to implement #async / #await in #C, for jobs running on a threadpool. Back then I said it only works when completion of the task resumes execution on the *same* pool thread.

Trying to improve overall performance, I found the complex logic to identify the thread job to put on a pool thread a real deal-breaker. Just having one single MPMC queue with a single semaphore for all pool threads to wait on is a lot more efficient. But then, a job continued after an awaited task will resume on a "random" thread.

It theoretically works by making sure to restore the CORRECT context (the original one of the pool thread) every time after executing a job, whether partially (up to the next await) or completely.

Only it didn't, at least here on #FreeBSD, and I finally understood the reason for this was that I was using #TLS (thread-local storage) to find the context to restore.

Well, most architectures store a pointer to the current thread metadata in a register. #POSIX user #context #switching saves and restores registers. I found a source claiming that the #Linux (#glibc) implementation explicitly does NOT include the register holding a thread pointer. Obviously, #FreeBSD's implementation DOES include it. POSIX doesn't have to say anything about that.

In short, avoiding TLS accesses when running with a custom context solved the crash. 🤯

Python friends:

I have a desire to build a small program for testing a piece of hardware I am designing. This program will need to have a REPL so the user can invoke various configuration and test commands while connected to the device, but also asynchronously handle data arriving from that device and displaying it.

Can anyone suggest packages and/or a strategy for doing this?

New Kitten update

🥳 Kitten HTML templates and kitten.Component render functions can now be async.

kitten.small-web.org

This is quite a big one and it took me finally biting the bullet and getting my head around generators in JavaScript to implement properly.

So now you can mix synchronous and asynchronous components as you like and if there are any asynchronous components in your templates they will automatically be awaited (even if you forget to use await) ;)

I’ll write a proper post/tutorial/documentation for it soon but for the time being enjoy the screenshots where a layout template gets the latest three posts from my mock fediverse public timeline service and displays them on the page.

The kitten.Component version also has a refresh button that streams a different three to the page.

For those of you unfamiliar with Kitten, this is all the code in either example. No scaffolding, nothing. Pop either into a file called index.page.js and run kitten in that folder and visit https://localhost to see the example run.

Enjoy!

:kitten:💕

Continued thread

for now, it pops up a scrolling table, based on data loaded by a multi-threaded indexing loop (doing concurrency in #rust is pretty enjoyable! no #async needed, either). lets you edit it (but crashes on backspace, lol). doesn't save it yet. pre-alpha stuff.

At a personal/professional level, having gotten to help *ship* this thing, by doing prepping the Book for the Edition and delivering a new (now stable! Go read it!) chapter on #async programming in #rustlang was huge.

This is never going to stop being amazing to me.

I need some obscure python help, fellow mastodonians:

I have a nested async function inside a regular function.

I need to test whether to await on it inside a decorator, but neither of `inspect` or `asyncio` helpers work, and .__code__.co_flags do not indicate it being a coroutine/awaitable/...

Right now I've added a flag to my decorator to manually control wrapped function behavior, but it's just a workaround.

Any tips? Thanks.

Replied in thread

@horusiath
Please can you elaborate? I'm about to use Actix as a localhost server which talks to an async linked API.

I asked both #Actix and #Axum Discords (the web framework from #tokio) if this was a good idea and both said yes, no problem which you use with #async - they both rely on tokio which is also what the #Rust API that I will be talking to uses.

I chose Actix for a basic test because it looks easier for a newbie to use.
#RustLang

Dear folks of #JavaScript #async #programming. This #Promise stuff is still voodoo to me. Any simple solution to set a timeout on this byte-receiving loop? I have to collect data from an USB IN endpoint... and let's assume(!) I don't know when I am done (how much data to receive) so that I always have to cancel the last started `transferIn` (#WebUSB) after a timeout (let's say 500 milliseconds). How would you do it? I've trued hacky Promise/timeout stuff, but don't feel comfortable with it.