Post the code below in a js object, then send the message poll to the object. It will check the state of the patch every 100 milliseconds. If you want to find out the state of the patch just once, send the message lockstate.
var polling = new Task(lockstate);
polling.interval = 100;