{"id":655,"date":"2025-07-21T12:12:34","date_gmt":"2025-07-21T12:12:34","guid":{"rendered":"https:\/\/tipcontrol.com\/?page_id=655"},"modified":"2025-07-21T12:12:34","modified_gmt":"2025-07-21T12:12:34","slug":"wait-function","status":"publish","type":"page","link":"https:\/\/tipcontrol.com\/?page_id=655","title":{"rendered":"wait function"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\"><code>wait(name, timeout)<\/code>&nbsp;Command Documentation<\/h3>\n\n\n\n<p>The <code>wait(name, timeout)<\/code> command is designed to pause program execution, waiting for a specific notification to be received. It listens for a notification identified by a given name, with the ability to specify a maximum wait time in milliseconds. If no notification is received within the specified timeout, the command returns <code>NIL<\/code>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Structure of the&nbsp;<code>wait<\/code>&nbsp;Command<\/h4>\n\n\n\n<p>The typical usage of the <code>wait<\/code> command is as follows:<\/p>\n\n\n\n<p><strong>Components<\/strong>:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong><code>name<\/code>\u00a0(String Literal)<\/strong>: Specifies the name of the notification to wait for. It must be a string literal that uniquely identifies the notification within the system.<\/li>\n\n\n\n<li><strong><code>timeout<\/code>\u00a0(Milliseconds)<\/strong>: An integer value representing the maximum time (in milliseconds) to wait for the notification. After this duration, if no notification is received, the function returns\u00a0<code>NIL<\/code>.<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">Simple Example<\/h4>\n\n\n\n<p>notification=NIL; \/\/ declare variable outside of loop<\/p>\n\n\n\n<p>dowhile(notification == NIL)<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>drv.digitalIO.toggle(); \/\/ toggle a LED for example<\/p>\n\n\n\n<p>&nbsp; &nbsp; \/\/ Wait for notification named &#8220;blink&#8221; for up to 1000 milliseconds<\/p>\n\n\n\n<p>&nbsp; notification = wait(&#8220;blink&#8221;, 1000);<\/p>\n\n\n\n<p>};<\/p>\n\n\n\n<p>lib.log(\u201cReceived stop notification: \u201c+notification);<\/p>\n\n\n\n<p><strong>Explanation<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Waiting for Notifications<\/strong>: The command waits for up to 1000 milliseconds for a notification named &#8220;blink&#8221;.<\/li>\n\n\n\n<li><strong>Handling NIL<\/strong>: If no notification is received within the timeout,\u00a0<code>NIL<\/code>\u00a0is returned, indicating a timeout.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Practical Use<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Asynchronous Event Handling<\/strong>: Use\u00a0<code>wait<\/code>\u00a0to synchronize with events or signals in a non-blocking manner, allowing programs to handle time-based or event-driven logic flexibly.<\/li>\n\n\n\n<li><strong>Timeout Mechanism<\/strong>: Incorporates a timeout to prevent indefinite waiting, ensuring that the program can continue execution even if an expected event does not occur.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Considerations<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>String Literal Requirement<\/strong>: The\u00a0<code>name<\/code>\u00a0parameter must be a string literal, ensuring consistent and unambiguous identification of notifications.<\/li>\n\n\n\n<li><strong>Timeout Specified in Milliseconds<\/strong>: Be sure to specify an appropriate timeout value depending on the responsiveness and expected behavior of the system or application.<\/li>\n<\/ul>\n\n\n\n<p>The <code>wait(name, timeout)<\/code> command provides a structured approach to coordinating program actions with external events, using notifications to enable asynchronous processing and improve program responsiveness.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>wait(name, timeout)&nbsp;Command Documentation The wait(name, timeout) command is designed to pause program execution, waiting for a specific notification to be received. It listens for a notification identified by a given name, with the ability to specify a maximum wait time in milliseconds. If no notification is received within the specified timeout, the command returns NIL. [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-655","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/pages\/655","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/tipcontrol.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=655"}],"version-history":[{"count":1,"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/pages\/655\/revisions"}],"predecessor-version":[{"id":656,"href":"https:\/\/tipcontrol.com\/index.php?rest_route=\/wp\/v2\/pages\/655\/revisions\/656"}],"wp:attachment":[{"href":"https:\/\/tipcontrol.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}