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

Libasynql question

Discussion in 'Development' started by Hipster, Jul 19, 2020.

  1. Hipster

    Hipster Zombie

    Messages:
    214
    Does libasynql uses the queue system(one after another) for executing the sql queries in an async way or are they randomly executed? I tried searching about this but couldnt find an answer on the repo.
     
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Short answer: this is undefined behaviour. There may be multiple queries running at undefined order at the same time, and the database engine decides how to handle concurrency.

    Long answer: libasynql uses a number of async workers, as specified in the config file. There is a global queue of queries to execute, and the workers will start executing the queries in the same order as scheduled. However, the order in which workers start executing is not the same as the order in which the database engine (e.g. MySQL server, or the filesystem locks for SQLite3) receives and actually runs the query. If there is only one query, it is less likely to have race conditions, but you should still not rely on this behaviour for correctness of queries.

    If you would like to ensure that queries are executed in order, you should execute the subsequent queries in the $onComplete parameter. Furthermore, libraries such as await-generator might help you achieving async callback in a more friendly syntax, but those have higher learning curve and are not recommended unless your program is primarily composed of complex callback logic.
     
    Hipster likes this.
  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.