mailio_imap_lock (mailio v0.2.0)

One session at a time on an IMAP connection. An IMAP connection has one selected mailbox, and a command such as UID STORE acts on whatever is selected when it arrives. A caller that selects a mailbox and then sends its command is safe only if nobody else selects another mailbox between the two. This lock is how callers that share one connection take turns: whoever holds it may select and send as many commands as it needs, the others wait in the order they asked. It is given up when the holder says so, when the holder dies, or when the connection does.

Summary

Functions

A lock for the connection ConnPid. It goes away with the connection.

Run Fun as the one session on the connection. Waits at most Timeout milliseconds for its turn: {error, imap_timeout} if it does not come.

Functions

handle_call(_, From, State)

handle_cast(Msg, State)

handle_info(Info, State)

init(ConnPid)

start_link(ConnPid)

-spec start_link(pid()) -> {ok, pid()}.

A lock for the connection ConnPid. It goes away with the connection.

stop(Lock)

-spec stop(pid()) -> ok.

with_session(Lock, Timeout, Fun)

-spec with_session(pid(), timeout(), fun(() -> Result)) -> Result | {error, term()}.

Run Fun as the one session on the connection. Waits at most Timeout milliseconds for its turn: {error, imap_timeout} if it does not come.