Hi,
I have a method sendEmail that is sending emails correctly and i decided
to call the method inside a Thread so I don't have to wait until the
email is sent but I don't know why it is not working, this is the code:
On Wed, 2013-10-09 at 14:59 +0200, Mario Ruiz wrote:
Hi,
I have a method sendEmail that is sending emails correctly and i decided
to call the method inside a Thread so I don't have to wait until the
email is sent but I don't know why it is not working, this is the code:
t = Thread.new do
sendEmail("blabla@hotmail.com","mysubject","mybody")
end
Thanks in advance
--
If you have received the message in error, please advise the sender by
reply email and please delete the message. This message contains
information which may be confidential or otherwise protected. Unless
you are the addressee (or authorized to receive for the addressee), you
may not use, copy, or disclose to anyone the message or any information
contained in the message.
Thread.join is what you're missing, although since you're only spawning
a single Thread, you're not really gaining anything there. You also set
"t" as the Thread, but you don't do anything with it.
Given the way you lay out your email body, you might want to look up
Heredocs as well.
Thanks
yep it seems the problem was the execution finish before finishing the
thread but in production is not going to end since it is a sinatra
script runnning all the time
thanks again
Your application (process) ends before the threads completes. I tried your
program, it seems you have an extra end. (sniper I ran : gist:9341b8684c56dccd3513 · GitHub )
I made it to wait if the thread is alive, after a while it send its mail. I
am not completely sure of it myself, but i guess the main program must
continue to be active. As the threads seems to die, as soon as the program
end.
I would suggest that you use a library for background processing rather
than implementing threads on your own, as such libraries would have a hook
to alert you incase they fail to complete.
On Wed, Oct 9, 2013 at 6:29 PM, Mario Ruiz <lists@ruby-forum.com> wrote:
Hi,
I have a method sendEmail that is sending emails correctly and i decided
to call the method inside a Thread so I don't have to wait until the
email is sent but I don't know why it is not working, this is the code: