Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A "Temporal Pass" Module

Tags:

erlang

I am trying to create a general module that collects data at an irregular interval. Data arrives from the left end as soon as new data has arrived. This may be something like 100 times a second.

On the right end I want to be able to "plug in" n listeners, each with its own regular interval. For the purpose of simplification, let's say all with an interval of once per second.

Every listener registers a callback function that may or may not be asynchronous.

My problem is that if the callback function is synchronous, my "temporal pass" may hang. What is the best way to approach this? Should I spawn a process whose pure purpose is to pass along the data and pay the price if the callback hangs?

         +-------------+ Data Out 1
=======> |Temporal Pass| ==========>
Data In  +-------------+ \\ Data Out 2
                          ++=======>
                           \\ Data Out n
                            ++=======>
like image 654
Magnus Kronqvist Avatar asked May 21 '26 06:05

Magnus Kronqvist


1 Answers

Spawn a new process for the message, otherwise the process will wait until synchronous calls are done. This is exactly the sort of problem the process model is meant to solve and I do not see any other way to do it.

Spawning processes are not expensive, but not entirely free either. You may get a small performance boost by only spawning new processes for the synchronous calls. That will require some way of flagging each callback as either synchronous or asynchronous.

like image 135
Emil Vikström Avatar answered May 25 '26 08:05

Emil Vikström



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!