# Ruby performing 2nd loop, before finishing 1st loop

**URL:** <https://www.ruby-forum.com/t/ruby-performing-2nd-loop-before-finishing-1st-loop/185347>\
**Category:** Ruby\
**Created:** [March 18, 2010, 2:43pm UTC](https://www.ruby-forum.com/t/ruby-performing-2nd-loop-before-finishing-1st-loop/185347 "2010-03-18T14:43:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pradeep\_236](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f9ae1b/32.png) [@pradeep\_236](https://www.ruby-forum.com/u/pradeep_236)\
**Post date:** [March 18, 2010, 2:43pm UTC](https://www.ruby-forum.com/t/ruby-performing-2nd-loop-before-finishing-1st-loop/185347/1 "2010-03-18T14:43:27Z")

</div>

Hi,

My code is like this:

if (row.abc1== ‘pnc’)

```
  action1

```

end

if (abc2 == ‘hjayu’)

```
   action2

```

end

Now the probelm is, before finishing the action1, it is going to perform  
action2 & resulting crashing the system.

what might be the problem, can somebody pls help

Thanks in advance  
apr

---

<div class="post-metadata">

**Author:** ![pradeep\_236](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f9ae1b/32.png) [@pradeep\_236](https://www.ruby-forum.com/u/pradeep_236)\
**Post date:** [March 18, 2010, 2:58pm UTC](https://www.ruby-forum.com/t/ruby-performing-2nd-loop-before-finishing-1st-loop/185347/2 "2010-03-18T14:58:17Z")

</div>

Does action1 run on a different thread than the one the method was  
called? Like:

def action1  
Thread.new do  
#your code here  
end  
end

Be wary that it might be that what happens inside action1 runs on a  
different thread, just not explicitly like this, for example it might  
call a library that runs its stuff on a separate thread. Could you show  
more of what happens inside action1() ?

–  
Andrea D.

> **[GitHub - bolthar/freightrain: Ruby desktop development made easy](https://github.com/bolthar/freightrain)**
>
> Ruby desktop development made easy. Contribute to bolthar/freightrain development by creating an account on GitHub.

> **[using (IMHO)](https://usingimho.wordpress.com)**
>
> Andrea Dallera 's blog

---

<div class="post-metadata">

**Author:** ![pradeep\_236](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f9ae1b/32.png) [@pradeep\_236](https://www.ruby-forum.com/u/pradeep_236)\
**Post date:** [March 18, 2010, 3:25pm UTC](https://www.ruby-forum.com/t/ruby-performing-2nd-loop-before-finishing-1st-loop/185347/3 "2010-03-18T15:25:24Z")

</div>

Andrea D. wrote:

> Does action1 run on a different thread than the one the method was  
> called? Like:
> 
> def action1  
> Thread.new do  
> #your code here  
> end  
> end
> 
> Be wary that it might be that what happens inside action1 runs on a  
> different thread, just not explicitly like this, for example it might  
> call a library that runs its stuff on a separate thread. Could you show  
> more of what happens inside action1() ?
> 
> –  
> Andrea D.  
> [GitHub - bolthar/freightrain: Ruby desktop development made easy](http://github.com/bolthar/freightrain)  
> [http://usingimho.wordpress.com](http://usingimho.wordpress.com)

Thanks for ur reply Andrea,

It is like this,

if (abc1 = fgd)  
click link1  
enter value1  
enter value2  
click ok  
end  
if (abc2 = fge)  
click link2  
select a check box1  
enter value1  
click ok  
end

Thanks  
apr

---

<div class="post-metadata">

**Author:** ![pradeep\_236](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f9ae1b/32.png) [@pradeep\_236](https://www.ruby-forum.com/u/pradeep_236)\
**Post date:** [March 18, 2010, 3:44pm UTC](https://www.ruby-forum.com/t/ruby-performing-2nd-loop-before-finishing-1st-loop/185347/4 "2010-03-18T15:44:32Z")

</div>

Hei,

> click ok  
> end

Still, i don’t understand what’s going on 🙂  
One quick and dirty (REALLY dirty) fix might be to check, before the  
abc2 == (mind the ==, NOT = ) fge condition evaluation, if the system is  
in a suitable state for the operation to be run and, if not, wait a  
little until it’s ready. Something like:

if (abc1 == fgd)  
click link1  
enter value1  
enter value2  
click ok  
end

while !operation\_over?  
sleep(1)  
end

if (abc2 = fge)  
click link2  
select a check box1  
enter value1  
click ok  
end

where operation\_over? is a method that you will have to write that  
checks for the system to be in a proper state: it should return true if  
the operation run after the first condition is over, false otherwise.  
But really, think twice before doing this: the problem you’re  
experiencing derives from some global value you’re changing, and  
global’s bad 🙂 i suggest you check for what’s going on deep under and  
fix the underlying problem instead of writing this hack.
