1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

"Await" using the new threading classes

Discussion in 'Development' started by XenialDan, Aug 26, 2018.

  1. XenialDan

    XenialDan Baby Zombie

    Messages:
    141
    GitHub:
    thebigsmilexd
    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?
     
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    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
     
    Last edited: Aug 27, 2018
    jasonwynn10 likes this.
  3. XenialDan

    XenialDan Baby Zombie

    Messages:
    141
    GitHub:
    thebigsmilexd
    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.
     
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    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.
     
  5. XenialDan

    XenialDan Baby Zombie

    Messages:
    141
    GitHub:
    thebigsmilexd
    As long as i can pass a SplQueue i am happy.
     
    Last edited: Aug 29, 2018
  6. XenialDan

    XenialDan Baby Zombie

    Messages:
    141
    GitHub:
    thebigsmilexd
    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?
     
  7. XenialDan

    XenialDan Baby Zombie

    Messages:
    141
    GitHub:
    thebigsmilexd
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.