({{, (RefLink[HandlerFunctions, paclet:ref/HandlerFunctions]) 
is an option for asynchronous operations that specifies functions to apply when events are generated.}})

OpenersNotesSection(Spacer1)Details

The typical setting for (RefLink[HandlerFunctions, paclet:ref/HandlerFunctions]) is \[LeftAssociation]"(Subscript[event, 1])"->(Subscript[f, 1]),"(Subscript[event, 2])"->(Subscript[f, 2]),…\[RightAssociation], which specifies that when (Subscript[event, i]) is generated, the function (Subscript[f, i]) should be applied to an association whose elements are specified by (RefLink[HandlerFunctionsKeys, paclet:ref/HandlerFunctionsKeys]).

The events that can be generated by particular tasks are listed under the functions that submit the tasks.

In the (RefLink[HandlerFunctions, paclet:ref/HandlerFunctions]) association, the special element "UnhandledEvent"->f uses the function f for any event for which no explicit handler was specified.

OpenersPrimaryExamplesSection(Spacer1)Examples  (8)

OpenersExampleSection0(Spacer1)Basic Examples  (8)

Display the result of evaluation after the task is finished:

SessionSubmit[Integrate[Log[t]^4/Sqrt[1-t^2],{t,0,1}],HandlerFunctions-><|"TaskFinished":>MessageDialog|>,HandlerFunctionsKeys->{"EvaluationResult"}]

Print the complete (RefLink[Association, paclet:ref/Association]) available to a handler function:

SessionSubmit[N[Pi,200],HandlerFunctions-><|"TaskFinished"->Print|>,HandlerFunctionsKeys->All]

Display the result of (RefLink[Print, paclet:ref/Print]) evaluated in a subkernel:

LocalSubmit[Print["Hello!"],
HandlerFunctions-><|"PrintOutputGenerated"->(Print[#PrintOutput]&)|>,
HandlerFunctionsKeys->{"EvaluationExpression","PrintOutput"}]

Display a dialog when a message is generated:

SessionSubmit[1/0,HandlerFunctions-><|"MessageGenerated"->MessageDialog|>,
HandlerFunctionsKeys->{"EvaluationExpression","MessageOutput"}]

Print messages generated by the subkernel:

LocalSubmit[1/0,HandlerFunctions-><|"MessageGenerated" -> (Message[#MessageOutput]&)|>,HandlerFunctionsKeys->{"MessageOutput"}]

Handle the "BodyReceived" event when it is generated by (RefLink[URLSubmit, paclet:ref/URLSubmit]):

URLSubmit["http://www.wolfram.com",HandlerFunctions-><|"BodyReceived"->Print|>]

Store the headers with a variable when they are received:

URLSubmit["http://www.wolfram.com",HandlerFunctions-><|"HeadersReceived"->((headers=#Headers)&)|>]

headers

Print the status code and content type when the task is finished:

URLSubmit["http://www.wolfram.com",HandlerFunctions-><|"TaskFinished"->Print|>, HandlerFunctionsKeys->{"StatusCode", "ContentType"}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[HandlerFunctionsKeys, paclet:ref/HandlerFunctionsKeys])  ▪  (RefLink[SessionSubmit, paclet:ref/SessionSubmit])  ▪  (RefLink[LocalSubmit, paclet:ref/LocalSubmit])  ▪  (RefLink[CloudSubmit, paclet:ref/CloudSubmit])  ▪  (RefLink[URLSubmit, paclet:ref/URLSubmit])  ▪  (RefLink[URLDownloadSubmit, paclet:ref/URLDownloadSubmit])  ▪  (RefLink[ChannelObject, paclet:ref/ChannelObject])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Background & Scheduled Tasks, paclet:guide/BackgroundAndScheduledTasks])}, {▪(RefLinkPlain[Channel-Based Communication, paclet:guide/Channel-BasedCommunication])}, {▪(RefLinkPlain[Date & Time, paclet:guide/DateAndTime])}, {▪(RefLinkPlain[Using Connected Devices, paclet:guide/UsingConnectedDevices])}, {▪(RefLinkPlain[HTTP Requests & Responses, paclet:guide/HTTPRequestsAndResponses])}})}})