Showing posts with label Multi-threading. Show all posts
Showing posts with label Multi-threading. Show all posts

Tuesday, 4 August 2015

CFML: revision to thread syntax (revisited)

G'day:
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
    }
});

Friday, 11 October 2013

CFML: A possible variation on the thread idea...

G'day:
I can't take sole credit for this idea, because when reading something Luis said today on the Railo Google Group, I had an epiphany. Let's have a look at <cfthread> (or, indeed, just thread) again...

Wednesday, 2 October 2013

CFML: Another suggested tweak to CFScript: thread

G'day:
Now I think there's a chance I'm having a "senior moment" here (which I hoped I'd not be getting for another 20-odd years, but hey-ho), as I'm sure I've discussed this before, but I can find no evidence of having done so.

CFScript's support for <cfthread> is another one of those weirdly-syntaxed things like savecontent:

thread name="t1" action="run" someattribute="value" {
    // stuff here
}

What I think this should be like is this:

t1 = Thread.new({someattribute="value"}) {
    // stuff here
}