⚲
Project
General
Profile
Sign in
Register
Home
Projects
Help
Search
:
Ruby master
All Projects
Ruby
»
Ruby master
Overview
Activity
Roadmap
Issues
Repository
Like
Download (1.05 KB)
Bug #5190
» thread_idle_loop.rb
hugobarauna (Hugo Baraúna)
, 08/12/2011 10:10 PM
require
'net/imap'
require
'rubygems'
require
'ruby-debug'
Net
::
IMAP
.
debug
=
true
class
EmailFetcher
def
self
.
start
$fetcher_thread
=
Thread
.
new
do
conn
=
Net
::
IMAP
.
new
(
"imap.gmail.com"
,
{
:port
=>
993
,
:ssl
=>
true
})
conn
.
login
(
"john.doe@gmail.com"
,
"password"
)
conn
.
select
(
"INBOX"
)
$receiver_thread
=
conn
.
instance_variable_get
(
:@receiver_thread
)
loop
do
conn
.
idle
do
|
response
|
if
response
.
kind_of?
(
Net
::
IMAP
::
UntaggedResponse
)
&&
response
.
name
==
'EXISTS'
puts
"Some emails arrived!"
conn
.
idle_done
end
end
puts
"Processing new emails"
end
end
end
end
EmailFetcher
.
start
$main_thread
=
Thread
.
current
loop
do
puts
"Threads "
+
Thread
.
list
.
join
(
", "
)
puts
"
\t
Main thread:
#{
$main_thread
}
, status
#{
$main_thread
.
status
}
"
puts
"
\t
Fetcher thread:
#{
$fetcher_thread
}
, status
#{
$fetcher_thread
.
status
}
"
if
$fetcher_thread
puts
"
\t
Receiver thread:
#{
$receiver_thread
}
, status
#{
$receiver_thread
.
status
}
"
if
$receiver_thread
puts
"
\n
"
sleep
(
10
)
end
« Previous
1
2
Next »
(2-2/2)
Loading...