[Seaside] ThreadPool with Seaside - how?

Ramon Leon ramon.leon at allresnet.com
Wed Jul 26 18:03:32 UTC 2017

On 07/26/2017 03:09 AM, Sabine Manaa wrote:
> -> this does not work.
> The generation of my reports needs the sessions objects.
> Also, calling another method of the session does not work.
> html mdlButton
> onClick:
> (html jQuery ajax
> script: [ :script | [ self session inspect ] queueWorkAndExpireIn: 25 
> seconds session: self session ]);
> with: '1'

I concur with Phillipe about being very careful using the session on a 
background thread as it's not meant to be thread safe and could 
potentially lead to concurrency bugs if you're not very careful; 
however, it's easy to do if you want to by simply using a closure.

| session |

"compute the current session and put into local var"

session := self session.

html mdlButton
	(html jQuery ajax
	   script: [ :script | [ session inspect ] queueWork ]);
     with: '1'

In other words don't access "self session" because that computes the 
session for the current thread which doesn't work on a background 
thread.  You can pass data to the background thread by having that data 
within the lexical scope of the block you launch as demonstrated above.

Calling fork would work just as well as queueWork, all the ThreadPool 
does is ensure there's a limited amount of background jobs running at 
any one time so you don't fork bomb yourself with too many threads and 
lock up your image.

Ramon Leon

More information about the seaside mailing list