Module: Fargo::Supports::RemoteFileList

Extended by:
ActiveSupport::Concern
Included in:
Client
Defined in:
lib/fargo/supports/remote_file_list.rb

Instance Method Summary collapse

Instance Method Details

#file_list(nick) ⇒ Object

Lazily load the file list for the nick. Subscribe to the client for the event :file_list to get notified.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fargo/supports/remote_file_list.rb', line 18

def file_list nick
  if @file_list.has_key?(nick)
    return parse_file_list(@file_list[nick], nick)
  elsif @getting_file_list[nick]
    return true
  end

  subscription_id = channel.subscribe do |type, map|
    case type
      when :download_finished, :download_failed, :connection_timeout
        if map[:nick] == nick
          @file_list[nick] = map[:file]

          channel.unsubscribe subscription_id
          channel << [:file_list,
              {:nick => nick, :list => @file_list[nick]}]

          @getting_file_list.delete nick
        end
    end
  end

  @getting_file_list[nick] = true
  download nick, 'files.xml.bz2'

  EventMachine.add_timer 60 do
    @file_list.delete nick
    @getting_file_list.delete nick
  end
end

#file_list!(nick, timeout = 10) ⇒ Object

Wait for the results to arrive, timed out after some time



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fargo/supports/remote_file_list.rb', line 50

def file_list! nick, timeout = 10
  if @file_list.has_key?(nick)
    return parse_file_list(@file_list[nick], nick)
  end

  list = nil
  list_gotten = lambda{ |type, map|
    if type == :file_list && map[:nick] == nick
      list = map[:list]
      true
    else
      false
    end
  }

  timeout_response(timeout, list_gotten){ file_list nick }

  parse_file_list list, nick
end