Blog Post

Using mask with timeout does not work

Wednesday, September 9, 2015 1:03 AM

I have come across a code which was as follows

 

util.setMask('body');

timeout('doLogic()', 1000);

util.removeMask('body');

 

This code was running great but the mask did not appear, and I was called to help.

 

What is the issue with this code?

The issue is that code does execute in order in which it is written.

util.setMask('body');

this line sets the  mask

timeout('doLogic()', 1000);

timeout does call method doLogic() after 1000 ms

util.removeMask('body');

remove mask gets executed right after the previous method gets processed and not after the timeout executes.

 

so the final correct code is:

util.setMask('body');

setTimeout(function(){
  doLogic();
  util.removeMask('body');
},1000);

Related articles by tags

Advert

Last posts

Advert