Revision f292535b
Added by Marc Dequènes about 14 years ago
- ID f292535b6365df76f1edd34bb6aeeb8e6f414614
lib/cyborghood/cyborg.rb | ||
---|---|---|
|
||
def ask_to_stop
|
||
logger.info "Bot was asked to stop..."
|
||
stop
|
||
try_stop
|
||
end
|
||
|
||
def ready_to_stop?
|
||
true
|
||
end
|
||
|
||
def stop
|
||
logger.info "Bot stopping"
|
||
EventMachine.stop
|
||
EventMachine.next_tick { EventMachine.stop_event_loop }
|
||
end
|
||
|
||
# core capabilities
|
||
... | ... | |
def schedule_task(callback, &task)
|
||
EventMachine.defer(task, callback)
|
||
end
|
||
|
||
protected
|
||
|
||
def try_stop
|
||
if ready_to_stop?
|
||
EventMachine.stop_event_loop
|
||
else
|
||
EventMachine.next_tick { try_stop }
|
||
end
|
||
end
|
||
end
|
||
|
||
autoload :BotNet, 'cyborghood/cyborg/botnet'
|
lib/cyborghood/cyborg/botnet.rb | ||
---|---|---|
def interface
|
||
EmptyInterface.instance
|
||
end
|
||
|
||
protected
|
||
|
||
def ready_to_stop?
|
||
@comm_list.empty?
|
||
end
|
||
end
|
||
end
|
lib/cyborghood/cyborg/conversation.rb | ||
---|---|---|
@comm_logic_block.call self unless @comm_logic_block.nil?
|
||
end
|
||
|
||
def set_comm_stop
|
||
def set_comm_stop(peer_left = false)
|
||
@comm_stop = true
|
||
yield if block_given?
|
||
close_connection_after_writing
|
||
peer_left ? close_connection : close_connection_after_writing
|
||
end
|
||
|
||
def set_error_status(fatal = false)
|
Also available in: Unified diff
[fix] ensure ask_to_stop() waits gracefully for conversations to finish while stop() just stopp at once