I'd like to get some proper explaination how the new Treads, sleeper and tasks work in PMMP 4.* on the master branch. Especially, how one could make a function that runs asyncronously and "yield"/give a value/result after it finished and runs a callback function. Also, are there ways to make it so that the callback function requests values/make modifications in the main thread?
PMMP 4.x has not been released yet, and it is still too early to talk about API changes on it. Please define "async", "await", "yield" and "threading". They are different concepts: "async" is an abstract concept that merely means "code is not executed immediately in the same control flow". It is also a term in ECMAScript 2017 specification used to describe a function that is automatically wrapped in a Promise. "await" is a term in ECMAScript 2017 used in ECMAScript 2017. It is just syntactic sugar used to replace Promise.then(). "yield" is a term related to generators. Generators are functions that can execute in separate synchronous phases with breakpoints at "yield" statements, and is controlled externally using an Iterator interface. "threading" is an operating system mechanism that executes a program with a separate set of resources. It has nothing to do with "async" and "yield". Please define your question better. Your question is too broad. You may be interested in https://GitHub.com/SOF3/await-generator
I basically asked for everything in that list. Especially, because i know that there is no real "async" in PHP, but hacks/workarounds to make threads act like they are asynchronous. I might explain what I'd like to do: I want to do some performance heavy calculations that take up to 30 seconds. I simply do not want to block the main thread with these calculations. The result of the calculations is then needed to perform actions in the main thread (entities and blocks will be affected). I saw the new sleepers in the test plugin, but i think those won't be there correct choice.
Do you actually understand what I'm saying? There are real threads in PHP using the pthreads extension. "async" is an abstract concept and is implemented differently in every language. Basically anything executed later, even on the same thread, can be called "async". Beware the cost of transferring data between threads. Very often, preparing for the data to be transferred into another thread and applying the results from a worker thread would be very high too, and would probably contradict with your initiative.
Bumping, because i have to add something. I've been a c# developer for some time now and recently got back to it. So i got in contact with "await <T> FunctionName" and coroutines. Are coroutines possible in PHP/PMMP?
Addition: finally understanding the concept of @SOFe 's await generator, thanks to this article: https://nikic.github.io/2012/12/22/Cooperative-multitasking-using-coroutines-in-PHP.html Is it possible to call it (a generator) from PMMP's Tasks?