Whilst messing around JavaScript Promises ("JavaScript: getting my brain around Promises" and "JavaScript: expectations re-adjusted re Promises") a week or so ago, I also started looking at how CFML's innate multi-threadedness, and how one would leverage this along with a CFML Promise implementation to be able to have clean & tidy & OO asynchronous code.
The general concept of firing off secondary threads in CFML is adequate, but I think the implementation leaves a bit to be desired. I'm going to forget the tag-based implementation as that is an artefact of more primitive times in CFML, and focus on the script implementation.
This is an example of lazy dull-headedness from the Adobe ColdFusion team who simply did a "tags-without-angle-brackets" implementation of
<cfthread>
for the script:thread name="t1" action="run" {
// stuff to run in its own thread here
}
This is just leaden.
A while back I mused about some improvements to the syntax ("CFML: Another suggested tweak to script:
thread
" and then "CFML: A possible variation on the thread
idea..."). Initially I just started out suggesting changing the syntax to be a hybrid of standard OO script syntax and tags-without-angle-brackets notation:t1 = Thread.new({someattribute="value"}) {
// stuff to run in its own thread here
}
And then further to this:
t1 = Thread.new(required function functionToRun, optional struct dataToPass, optional struct eventHandlers);
This would result in code like this:
t1 = Thread.new(function(){
// stuff to run in its own thread here
}, {}, {
success = function(){
// stuff to do after the first function finishes
},
failure = function(){
// stuff to do after the first function fails
}
});