Wolfram Research

Function Repository Resource:

ChannelMessages

Source Notebook

Send relevant data to a channel object when a message occurs

Contributed by: Richard Hennigan (Wolfram Research)

ResourceFunction["ChannelMessages"][eval,channel]

sends message data to channel when a message occurs during evaluation of eval.

ResourceFunction["ChannelMessages"][eval,{channel1,channel2,}]

sends message data to the channels channel1,channel2,.

Examples

Basic Examples

Listen to a channel for message data:

In[1]:=
listener = ChannelListen["MessageChannel", (message = ReleaseHold[#Message]) &]
Out[1]=

Send message data to the channel when messages occur:

In[2]:=
ResourceFunction["ChannelMessages"][1/0, "MessageChannel"]
Out[2]=

Print the message:

In[3]:=
message["Message"]

View the full data in a notebook:

In[4]:=
NotebookPut[ResourceFunction["AssociationNotebook"][message]]
Out[4]=

Applications

Redirect messages from a deployed APIFunction to the current session:

In[5]:=
ChannelListen[
  "MessageChannel", (SessionSubmit[
     ReleaseHold[#Message]["Message"]]) &];
In[6]:=
api = CloudDeploy[
  APIFunction[{"x" -> "Number", "y" -> "Number"}, ResourceFunction["ChannelMessages"][#x/#y, "MessageChannel"] &]]
Out[6]=

Messages from the API will print in the current session:

In[7]:=
URLExecute[api, {"x" -> 1, "y" -> 0}]
Out[7]=
In[8]:=
URLExecute[api, {"x" -> 0, "y" -> 0}]
Out[8]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

See Also

License Information