raymondcamden
10/03/2023, 4:01 PMseancorfield
raymondcamden
10/03/2023, 4:32 PMseancorfield
raymondcamden
10/03/2023, 4:33 PMraymondcamden
10/03/2023, 4:34 PMseancorfield
seancorfield
raymondcamden
10/03/2023, 4:36 PMraymondcamden
10/03/2023, 4:36 PMseancorfield
raymondcamden
10/03/2023, 4:38 PMseancorfield
seancorfield
seancorfield
runAsync()
is kind of a dumb API over Java's CompleteableFuture
so it's about the best CF has had so far.seancorfield
runAsync()
in CF) and then calls .get()
on each of those three futures to get the query result back.
Each SQL query will run in a separate thread and the main thread will then wait for each thread to finish, so it'll run in the time of the slowest query rather than the sum of the time of the three queries.
Or you could run two queries in futures, and run one in the main thread, and then wait on the other two. Uses one less thread but also means the main thread can't do other work while the queries are running (we actually run a couple of simple queries one after the other in the main thread because we know their total time will be less than the slowest of the three big queries.
Does that help frame a real world situation @raymondcamden?raymondcamden
10/03/2023, 5:05 PMseancorfield
raymondcamden
10/03/2023, 5:21 PMwebsolete
10/03/2023, 7:24 PMJonas Eriksson
10/04/2023, 8:32 AMseancorfield
bdw429s
10/04/2023, 4:59 PMrunasync()
examples may have come from the Adobe docs. The source for the book is here
https://github.com/ortus-docs/Modern-ColdFusion-CFML-In-100-Minutes/blob/master/beyond-the-100/asynchronous-programming.md
Pull requests welcome 🙂
That said, we've never really used runasync() at Ortus and don't care much for it. We've written our own async framework as a direct wrapper around Java's Completable Futures which we prefer and is documented in part here:
https://coldbox.ortusbooks.com/digging-deeper/promises-async-programming
which allow for things like this:
// Parallel Executions
async().all(
() => <http://hyper.post|hyper.post>( "/somewhere" ),
() => <http://hyper.post|hyper.post>( "/somewhereElse" ),
() => <http://hyper.post|hyper.post>( "/another" )
).then( (results)=> logResults( results ) );
If you scroll down on that last page, we actually cover the main difference between cfthread, runasync, and our AsnyncManager (which comes with ColdBox, WireBox, CacheBox, and LogBox.) We tapped into much of the concurrent package and even have a task scheduling engine in ColdBox built on scheduled executors:
https://coldbox.ortusbooks.com/digging-deeper/promises-async-programming/scheduled-tasks
Anyway, long story short, we've never been super impressed with any of CFML's built in threading and have basically built our own wrappers around the JDK's to harness what it offers.seancorfield
runAsync()
to anyone either...Mark Takata (Adobe)
10/06/2023, 8:48 PMsaghosh
10/10/2023, 11:21 AM