Yeah, once again I'm empressed by the power and beauty of Erlang. This time I've had to solve the task that all services inside the Tideland EAS have got no problem to talk asynchronously between each other while external event publishers had no chance to receive possible answers. So I developed the temporary event listener which subscribes - as the name is already implies - temporarilly to a channel and a topic together with a given timeout using eastel:new(Channel, Topic, Timeout). It immediately starts to collect the events it receives. Now the publisher can send his event. Afterwards it can fetch the fist matching received event using eastel:first(FMatch, TelId). If it has already been received the function will call immediately. Otherwise it will wait until either the right event will be received or otherwise the time is over. Really nice.
The whole thing is a combination of a gen_server, pattern matching, and funs. And it's a real simple and compact piece of code. In most environments it would have been a more complex solution. And I think only Smalltalk would be a good candidate for an alternative implementation, with more code, but also with a better readibility.
0 Comments:
Post a Comment