Re: [Wtr-general] Concurrent Threads and different variables in each thread

2007-07-11 Thread marekj

if you don't join the threads the execution will stop when program exists.


On 7/11/07, Jason <[EMAIL PROTECTED]> wrote:


Ahhh... maybe, just MAYBE, I should try something before I give up and
post.

This appeared to work:

> require 'thread'
> require 'watir'
>
> @var1='pickaxe'
> @var2='axepick'
> @var3='pckexai'
>
> def test_google(varvar)
>  ie = Watir::IE.start('http://www.google.com')
>  ie.text_field(:name, "q").set(varvar)
>  ie.button(:value, "Google Search").click
>  ie.html
>  ie.close
> end
>
> a=Thread.new {test_google(@var1)}
> b=Thread.new {test_google(@var2)}
> c=Thread.new {test_google(@var3)}
> a.join
> b.join
> c.join

It's not pretty, and if I wanted 5 or 20 threads it would mean writing
these lines of code 10 or 40 times.  Must be a cleaner way?
___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

Re: [Wtr-general] Concurrent Threads and different variables in each thread

2007-07-11 Thread Paul Rogers
Must be a  cleaner way? 
Yes - an array - you'll figure it out ;-)


- Original Message -
From: Jason <[EMAIL PROTECTED]>
Date: Wednesday, July 11, 2007 9:37 am
Subject: Re: [Wtr-general] Concurrent Threads and different variables in    
each thread
To: wtr-general@rubyforge.org

> Ahhh... maybe, just MAYBE, I should try something before I give 
> up and post.
> 
> This appeared to work:
> 
> > require 'thread'
> > require 'watir'
> > 
> > @var1='pickaxe'
> > @var2='axepick'
> > @var3='pckexai'
> > 
> > def test_google(varvar)
> >  ie = Watir::IE.start('http://www.google.com')
> >  ie.text_field(:name, "q").set(varvar)
> >  ie.button(:value, "Google Search").click
> >  ie.html
> >  ie.close
> > end
> > 
> > a=Thread.new {test_google(@var1)}
> > b=Thread.new {test_google(@var2)}
> > c=Thread.new {test_google(@var3)}
> > a.join
> > b.join
> > c.join
> 
> It's not pretty, and if I wanted 5 or 20 threads it would mean 
> writing these lines of code 10 or 40 times.  Must be a 
> cleaner way?
> ___
> Wtr-general mailing list
> Wtr-general@rubyforge.org
> http://rubyforge.org/mailman/listinfo/wtr-general
>
___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

Re: [Wtr-general] Concurrent Threads and different variables in each thread

2007-07-11 Thread Jason
Ahhh... maybe, just MAYBE, I should try something before I give up and post.

This appeared to work:

> require 'thread'
> require 'watir'
> 
> @var1='pickaxe'
> @var2='axepick'
> @var3='pckexai'
> 
> def test_google(varvar)
>  ie = Watir::IE.start('http://www.google.com')
>  ie.text_field(:name, "q").set(varvar)
>  ie.button(:value, "Google Search").click
>  ie.html
>  ie.close
> end
> 
> a=Thread.new {test_google(@var1)}
> b=Thread.new {test_google(@var2)}
> c=Thread.new {test_google(@var3)}
> a.join
> b.join
> c.join

It's not pretty, and if I wanted 5 or 20 threads it would mean writing these 
lines of code 10 or 40 times.  Must be a cleaner way?
___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general


[Wtr-general] Concurrent Threads and different variables in each thread

2007-07-11 Thread Jason
What would you suggest for running mutiple threads, BUT each thread using 
different variables.  I've 'stolen' the following code from Brett (thanks!) 
which does exactly as expected, BUT how would I, for instance, search for a 
different value (instead of 'pickaxe') in each thread?

> require 'thread'
> require 'watir'
> 
> def test_google
>ie = Watir::IE.start('http://www.google.com')
>ie.text_field(:name, "q").set('pickaxe')
>ie.button(:value, "Google Search").click
>ie.html
>ie.close
> end
> 
> threads = []
> 3.times do
>threads << Thread.new {test_google}
> end
> threads.each {|x| x.join}

Could I pass some arguments to +Thread.new(args)+, or should I simply create 3 
threads as such:

>  a = Thread.new { yada yada }
>  b = Thread.new { yada yada }
>  c = Thread.new { yada yada }

I also don't quite understand why the *threads.each {|x| x.join}* command 
exists ?
___
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general