Skip to content

Instantly share code, notes, and snippets.

@bcoe
Last active Aug 29, 2015
Embed
What would you like to do?
Semaphore using EventMachine gratifications.
# Execute an IMAP command from the frontend
# API on a specific user's ImapConnection.
#
# @param command [symbol] the command to execute.
# @param params [Hash] the parameters for the command.
def execute_imap_command(command, params)
log_info("executing #{command} for #{email}")
# we should re-select the mailbox
# once per command executed.
@imap_connection.mailbox = nil
previous_command = @previous_command
# Use EM gratifications to create a mutex on imap commands.
if previous_command && previous_command.instance_variable_get(:@deferred_status) == :unknown
@previous_command = previous_command.
bind! do
@imap_connection.send(command, params)
end
else
@previous_command = @imap_connection.send(command, params)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment