<DIV>> > Hello!<BR>> > <BR>> > I have to implement function a() which have to call function b().<BR>> > Function a() is always called from a mnesia transaction, while <BR>> > functionb() can't be called from a mnesia transaction. How can <BR>> I <BR>> > solve this<BR>> > problem elegantly? My idea is start a process from a(), send a <BR>> message> to the process, which in turn will call b() (it's now <BR>> outside of the<BR>> > transaction, right?) and when b() returns, the process sends <BR>> > back a<BR>> > message to a(). Is there a simpler way to solve the problem?<BR>> <BR>> Sending message from a transaction is a bad idea --- in fact any <BR>> side-effect inside transaction is a bad idea --- if the <BR>> transaction have to be restarted (which Mnesia does <BR>> automatically if need arises). Then there would be several <BR>> messages sent to the process calling the function b(). <BR>> <BR>> I wonder if there's elegant solution to this, but perhaps <BR>> restricting Mnesia transactions to only one (somewhere was such <BR>> parameter) </DIV>
<DIV> </DIV>
<DIV>I meant "... only one transaction and checking if it succeeded. If not, some recovery action should take place."</DIV>
<DIV> </DIV>
<DIV>But I think that the actual details of the two functions dictates the suitable solution and my ideas here are just hacks that might work or not depending on the details.</DIV>
<DIV> </DIV>
<DIV>>or giving some unique identifier outside of <BR>> transaction containing the function a() which is sent with the <BR>> message to process calling the b(). Then, if b receives the same <BR>> identifier twice (or more times if Mnesia restarts the <BR>> transaction several times) it discards such calls, but returns <BR>> the previous answer. A bit hacky, I have to admit, but it's been <BR>> some years that I had to study the subject during my thesis. I'm <BR>> interested in hearing the "correct" solution from pros :)<BR>> <BR>> >                           Bye,NAR<BR>> > -- <BR>> > "Beware of bugs in the above code; I have only proved it <BR>> > correct, not<BR>> >   tried it."<BR>> > _______________________________________________<BR>> > erlang-questions mailing list<BR>> > erlang-questions@erlang.org<BR>> > http://www.erlang.org/mailman/listinfo/erlang-questions<BR>> <BR>> <BR>> Jani Launonen<BR></DIV>
<DIV> </DIV>