sueden.social ist einer von vielen unabhängigen Mastodon-Servern, mit dem du dich im Fediverse beteiligen kannst.
Eine Community für alle, die sich dem Süden hingezogen fühlen. Wir können alles außer Hochdeutsch.

Serverstatistik:

1,8 Tsd.
aktive Profile

#async

2 Beiträge2 Beteiligte0 Beiträge heute

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.
#PHP#Coroutines#Async

JavaScript, wow!🤣

I was under the impression that if a function returns a Promise, it never throws. Rather, in any case, it returns a Promise, rejected if the functions throws something.

But fetch() is a counter-example. Or this on the TypeScript playground:

typescriptlang.org/play/?#code

The crucial thing is. My impression above is true for functions of the form

async f(...): Promise<...> { ... }

Just add the async in the playground to see the difference.

www.typescriptlang.orgTS Playground - An online editor for exploring TypeScript and JavaScriptThe Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
#code#TypeScript#async

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 - cat(1) echo server
Fortgeführter 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. 🤯