Last active
August 29, 2015 13:56
-
-
Save bcoe/9094018 to your computer and use it in GitHub Desktop.
Semaphore using EventMachine gratifications.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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