= AsyncControl _(record)_
:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Modifies the way in which an asynchronous action initiated through the xref:refguide:applib:index/services/wrapper/WrapperFactory.adoc[WrapperFactory] is actually executed.

Executing in a separate thread means that the target and arguments are used in a new _org.apache.causeway.applib.services.iactn.Interaction_ (and transaction). If any of these are entities, they are retrieved from the database afresh; it isn't possible to pass domain entity references from the foreground calling thread to the background threads.

== API

[source,java]
.AsyncControl.java
----
record AsyncControl {
  AsyncControl defaults()
  AsyncControl withExecute()     // <.>
  AsyncControl withNoExecute()     // <.>
  AsyncControl withSkipRules()     // <.>
  AsyncControl withCheckRules()
  AsyncControl withExceptionHandler(ExceptionHandler exceptionHandler)     // <.>
  AsyncControl with(ExecutorService executorService)     // <.>
  AsyncControl listen(SyncControl.@NonNull CommandListener commandListener)
  AsyncControl withClock(VirtualClock clock)     // <.>
  AsyncControl withLocale(Locale locale)     // <.>
  AsyncControl withTimeZone(ZoneId timeZone)     // <.>
  AsyncControl withUser(UserMemento user)     // <.>
  InteractionContext override(InteractionContext interactionContext)
}
----

<.> xref:#withExecute_[withExecute()]
+
--
Explicitly set the action to be executed.
--
<.> xref:#withNoExecute_[withNoExecute()]
+
--
Explicitly set the action to _not_ be executed, in other words a 'dry run'.
--
<.> xref:#withSkipRules_[withSkipRules()]
+
--
Skip checking business rules (hide/disable/validate) before executing the underlying property or action
--
<.> xref:#withExceptionHandler_ExceptionHandler[withExceptionHandler(ExceptionHandler)]
+
--
How to handle exceptions if they occur, using the provided xref:refguide:applib:index/services/wrapper/control/ExceptionHandler.adoc[ExceptionHandler] .
--
<.> xref:#with_ExecutorService[with(ExecutorService)]
+
--
Specifies the _ExecutorService_ to use to obtain the thread to invoke the action.
--
<.> xref:#withClock_VirtualClock[withClock(VirtualClock)]
+
--
Defaults to the system clock, if not overridden
--
<.> xref:#withLocale_Locale[withLocale(Locale)]
+
--
Defaults to the system locale, if not overridden
--
<.> xref:#withTimeZone_ZoneId[withTimeZone(ZoneId)]
+
--
Defaults to the system time zone, if not overridden
--
<.> xref:#withUser_UserMemento[withUser(UserMemento)]
+
--
Specifies the user for the session used to execute the command asynchronously, in the background.
--

== Members

[#withExecute_]
=== withExecute()

Explicitly set the action to be executed.

[#withNoExecute_]
=== withNoExecute()

Explicitly set the action to _not_ be executed, in other words a 'dry run'.

[#withSkipRules_]
=== withSkipRules()

Skip checking business rules (hide/disable/validate) before executing the underlying property or action

[#withExceptionHandler_ExceptionHandler]
=== withExceptionHandler(ExceptionHandler)

How to handle exceptions if they occur, using the provided xref:refguide:applib:index/services/wrapper/control/ExceptionHandler.adoc[ExceptionHandler] .

The default behaviour is to rethrow the exception.

[#with_ExecutorService]
=== with(ExecutorService)

Specifies the _ExecutorService_ to use to obtain the thread to invoke the action.

The default is _null_ , indicating, that its the xref:refguide:applib:index/services/wrapper/WrapperFactory.adoc[WrapperFactory] 's responsibility to provide a suitable _ExecutorService_ .

[#withClock_VirtualClock]
=== withClock(VirtualClock)

Defaults to the system clock, if not overridden

[#withLocale_Locale]
=== withLocale(Locale)

Defaults to the system locale, if not overridden

[#withTimeZone_ZoneId]
=== withTimeZone(ZoneId)

Defaults to the system time zone, if not overridden

[#withUser_UserMemento]
=== withUser(UserMemento)

Specifies the user for the session used to execute the command asynchronously, in the background.

If not specified, then the user of the current foreground session is used.
