Give me true async for PHP 9.0
To pin or to unpin, that is truly the question
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:
https://doeken.org/blog/coroutines-in-php?utm_source=mastodon
How I normally do #async external programs in my #commonLisp image #embeddableCommonLisp and #uiop (in the notes).
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.
@noboilerplate THIS!
I think a lot of people inadvertently assume async #RustLang is so different from sync Rust, because the way it is - when in fact it's because of the (most popular) async runtime they're using.
We should look way more into alternative #async runtimes to #Tokio, e.g. smol:
https://floss.social/@janriemer/111669258656959538
#Smol allows you to use non-'static Futures by using a local executor:
https://floss.social/@janriemer/111669668856899636
It looks a lot more like "normal" #Rust.
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.
Do any operating systems other than #Linux (#Windows, #macOS, #FreeBSD, #OpenBSD, etc) have an API for non-blocking file IO?
I know Linux has that in #io_uring, which can do almost any IO operation (even fsync) in the background and tell you when it's done, but is that the only OS with such a feature?
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.
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!
Note to self: you can't `try...catch` an `await func();` in Javascript.
Apparently it's time I got some understanding of Arc, RwLock and Mutex, because I can't figure out if I need Arc to use concread::ARCache from #async functions.
It says it's a replacement for the latter two, but the only example I found wraps it in an Arc.
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.
@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.