Generating unique ids in Mnesia

Håkan Huss huss01@REDACTED
Thu Aug 18 21:33:32 CEST 2005


2005/8/18, Joel Reymont <joelr1@REDACTED>:
> I think I solved the problem. I'll rely on a separate counter table
> and mnesia:dirty_update_counter().

Why not just have a process which on request returns ever increasing numbers.
Something like:

-module(seqserver).

-export([init/0, init/1, next/1]).

init() -> init(0).

init(N) ->
    spawn(fun () -> loop(N) end).

next(Seqserver) ->
    Seqserver ! {self(), next},
    receive
        {Seqserver, N} -> N
    end.

loop(N) ->
    receive
        {Pid, next} ->
            Pid ! {self(), N},
            loop(N + 1);
        _Other ->
            loop(N)
    end.

/Håkan



More information about the erlang-questions mailing list