Running futures at user background priority

Long running futures executed at the same priority as futures used by the user interface can slow down the entire user interface.

AsyncFutureExecutionUserBackgroundPriority AsyncFutureExecutionPriority << #AsyncFutureExecutionUserBackgroundPriority slots: {}; tag: 'Executor'; package: 'Futures' is a priority for futures that is lower than the lowest priority used by the user interface.

The simplest way to execute a computation in a worker process at this priority is using BlockClosure>>#asAsyncPromiseWithUserBackgroundPriority asAsyncPromiseWithUserBackgroundPriority ^ self asAsyncFuture awaitWithUserBackgroundPriority .

promise := [ 50000 factorial ] asAsyncPromiseWithUserBackgroundPriority
  
promise := [ 50000 factorial ] asAsyncFuture
	awaitWithUserBackgroundPriority
  

If more control is needed over these computations thet can be run also in dedicated workers.

promise := [ 50000 factorial ] asAsyncFuture
	awaitWithUserBackgroundPriorityInCustomGroup: #MyWorker
  
promise := [ 50000 factorial ] asAsyncFuture
	await: (AsyncFutureExecutionConfiguration new 
		userBackgroundPriority;
		customGroup: #MyWorker)
  

In case multiple such computations are needed and they might also need to wait for the results of other computations, one further option is to use BlockClosure>>#asAsyncForkedFuture asAsyncForkedFuture ^ AsyncForkPollFuture pollBlock: self to create futures that run in their own process instead of the worker process.

promise := [ 50000 factorial ] asAsyncForkedFuture
	awaitWithUserBackgroundPriority
  

In the code snippet below the worker is responsible for managing the execution of the future in a dedicated process. While the future runs, the worker is free to execute other futures.

promise := [ 50000 factorial ] asAsyncForkedFuture
	await: (AsyncFutureExecutionConfiguration new 
		userBackgroundPriority;
		customGroup: #MyWorker)