# Signaling VS polling

**URL:** <https://forum.kirupa.com/t/signaling-vs-polling/219575>\
**Category:** flash\
**Created:** [March 18, 2007, 3:24am UTC](https://forum.kirupa.com/t/signaling-vs-polling/219575 "2007-03-18T03:24:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NeoDreamer](https://avatars.discourse-cdn.com/v4/letter/n/ccd318/32.png) [@NeoDreamer](https://forum.kirupa.com/u/NeoDreamer)\
**Post date:** [March 18, 2007, 3:24am UTC](https://forum.kirupa.com/t/signaling-vs-polling/219575/1 "2007-03-18T03:24:52Z")

</div>

Let’s pretend that I’m making a game where the character can move left or right. Currently, I only know how to do polling to detect a key press. Here is some psuedocode.

[AS]  
while(1){  
if(key == left)  
moveCharacterLeft();  
else  
moveCharacterRight();  
}  
[/AS]

This is inefficient because it wastes CPU cycles when no keys are presed. In my computer science OS class, we recently learned about about signaling. It’s basically the above code without the while loop. The program does not repeatedly check what keys are pressed, rather the function is notified when a key is pressed. Is there an equivalent signaling method in actionscript?
