Forcing stuff in background threads is really easy. As Fr0st mentioned earlier the real challenge is converting everything to be thread-safe. We have two options here:Scalmax wrote: ↑07.07.2023, 18:15Any async code inside Zeos will add much of complicated code and create classes, that do many things. Clearly, it is not a good design.
Have a look at APL in TComponent. Or System.Net.Socket.TSocket. Begin*() all over the code. What for? ZMethodInThread is good enough for start.
In this context TZMemTable is a blessing: run query in background, as a result copy it in sync manner to TZMemTable.
1, Take the concept only and build everything up from 0. Codebase perspective this is a better solution as everything will be designed with thread-safety in mind. However it is extremely time- and resource consuming, and it effectively would be a different component at the end.
2, Patch things until they work. This is the quicker solution as you keep 80-90% of the existing code. Con is, the solution will be more complex, less robust and more prone to bugs.
Considering the small team behind Zeos; if we ever start moving toward async, it will be option #2 and the code will be more complex at the end.
The concept of ZMethodInThread (and my later full-blown worker threads) do exactly that; I even implemented calling .AbortOperation on the connection if .Terminate gets called on the thread.Scalmax wrote: ↑07.07.2023, 18:15In the end, people will use their own threads, just give them ability to thread-safely AbortOperation(). The real question is: can we call AbortOperation() from another thread using the same connection. In TZPostgreSQLConnection implementation it uses: FConn, FLogMessage, HandleErrorOrWarning(). Or asking another way: what operations of zeos classes that use Connection can affect those fields/method? My small knowlegle of Zeos and gut feeling tells me that those 2 questions are apt for another forum thread (with pun intended).
As for your concerns about .AbortOperation I'm not sure I get what you mean. Some libraries require a different connection (like MySQL) and that is already being taken care of by Zeos. I personally tested MySQL, Oracle, MSSQL (via DBLib) and SQLite; calling .AbortOperation from the VCL thread's context always worked and brought the expected results.