Jump to content

Register a notifier as a user event


bjustice

Recommended Posts

I made a fun piece of code, and thought that I'd share.  Maybe it'll spark some good discussion.  Here it is:

Push-Notifier.zip

 

I wanted to accomplish 2 things with this code:

1) I wanted to be able to create a notifier that I can register as a user event.  Basically, I want a user event to be generated whenever a new notification is sent.

2) When I register for a user event, I want to be able to also force the event structure to generate a user event using the most recent notification.  (Helpful for initialization of data in the event structure)

 

Demo VI looks like this:

10.png.75b2866c23f6b94d32c423a43501ec0e.png

 

Anyways, thought this might be fun to share

 

  • Thanks 1
Link to comment
11 hours ago, bjustice said:

When I register for a user event, I want to be able to also force the event structure to generate a user event using the most recent notification.  (Helpful for initialization of data in the event structure)

This is very useful behavior, as it simplifies initialization code quite a lot, and eliminates almost all worries about "who starts first" among communicating modules. I have a similar feature in Messenger Library; I call it a "State Notification" as distinct from an "Event Notification", as the type of data where one needs the most recent value is state data.

Edited by drjdpowell
Link to comment

drjdpowell touched upon the primary (and initial) purpose for the code.  I had an issue where I wanted to use user events, but the rule of "who starts first" came into play.  This eliminated that worry.  I could spin up a sub-process, register it for the user event, and force the user event case (only in that subprocess) to initialize with the most recent data.  And, it's clean!  Notice how I'm able to share the "mycluster" user event case structure with both the initialization UE and the normal UE.  No tacky need for another case structure event that only handles first call initialization, or some other similar thing.

Link to comment

To make sure no Events are lost I usually just register the user event at the moment of creation and pass out the event registration refnum for the event.  Then, any events sent before the Event loop is running are not lost, they are stored within the event registration refnum queue.

A different idea is the ability to get the last sent value.  I typically involve the event loop in this as it "owns" the values and other processes may actually update the values (such as internal consistency checks) so that the last "sent" value is not actually up-to-date.  But I canunderstand the idea behind being able to efficiently get this value back.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.