ui.tools.listener: only wait up to 5 seconds for the listener to start

otherwise unit tests can wait forever if there is an error in listener-thread
db4
Björn Lindqvist 2015-11-27 13:15:17 +01:00
parent 867c85f1c5
commit 686975ec29
3 changed files with 18 additions and 10 deletions

View File

@ -1,6 +1,6 @@
! Copyright (C) 2008 Slava Pestov. ! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax ; USING: calendar concurrency.conditions help.markup help.syntax ;
IN: concurrency.flags IN: concurrency.flags
HELP: flag HELP: flag
@ -10,6 +10,10 @@ HELP: <flag>
{ $values { "flag" flag } } { $values { "flag" flag } }
{ $description "Creates a new flag." } ; { $description "Creates a new flag." } ;
HELP: lower-flag
{ $values { "flag" flag } }
{ $description "Attempts to lower a flag. If the flag has been raised previously, returns immediately, otherwise waits for it to be raised first." } ;
HELP: raise-flag HELP: raise-flag
{ $values { "flag" flag } } { $values { "flag" flag } }
{ $description "Raises a flag, notifying any threads waiting on it. Does nothing if the flag has already been raised." } ; { $description "Raises a flag, notifying any threads waiting on it. Does nothing if the flag has already been raised." } ;
@ -18,9 +22,9 @@ HELP: wait-for-flag
{ $values { "flag" flag } } { $values { "flag" flag } }
{ $description "Waits for a flag to be raised. If the flag has already been raised, returns immediately." } ; { $description "Waits for a flag to be raised. If the flag has already been raised, returns immediately." } ;
HELP: lower-flag HELP: wait-for-flag-timeout
{ $values { "flag" flag } } { $values { "flag" flag } { "timeout" duration } }
{ $description "Attempts to lower a flag. If the flag has been raised previously, returns immediately, otherwise waits for it to be raised first." } ; { $description "Waits for a flag to be raised or throws a " { $link timed-out-error } " if the flag wasn't raised in time." } ;
ARTICLE: "concurrency.flags" "Flags" ARTICLE: "concurrency.flags" "Flags"
"A " { $emphasis "flag" } " is a condition notification device which can be in one of two states: " { $emphasis "lowered" } " (the initial state) or " { $emphasis "raised" } "." "A " { $emphasis "flag" } " is a condition notification device which can be in one of two states: " { $emphasis "lowered" } " (the initial state) or " { $emphasis "raised" } "."

View File

@ -1,7 +1,7 @@
USING: help.markup help.syntax help.tips io kernel listener USING: help.markup help.syntax help.tips io kernel listener sequences
ui.commands ui.gadgets ui.gadgets.editors ui.gadgets.panes ui.commands ui.gadgets.editors ui.gadgets.panes ui.operations
ui.operations ui.tools.common ui.tools.listener.completion vocabs ui.tools.common ui.tools.listener.completion vocabs vocabs.refresh
vocabs.refresh words ; words ;
IN: ui.tools.listener IN: ui.tools.listener
HELP: <listener-gadget> HELP: <listener-gadget>
@ -24,9 +24,13 @@ HELP: interactor-busy?
{ $values { "interactor" interactor } { "?" boolean } } { $values { "interactor" interactor } { "?" boolean } }
{ $description "We're busy if there's no thread to resume." } ; { $description "We're busy if there's no thread to resume." } ;
HELP: interactor-read
{ $values { "interactor" interactor } { "lines" sequence } }
{ $description "Implements the " { $link stream-readln } " generic for the interactor." } ;
HELP: wait-for-listener HELP: wait-for-listener
{ $values { "listener" listener-gadget } } { $values { "listener" listener-gadget } }
{ $description "Wait for the listener to start." } ; { $description "Wait up to five seconds for the listener to start." } ;
ARTICLE: "ui-listener" "UI listener" ARTICLE: "ui-listener" "UI listener"
"The graphical listener adds input history and word and vocabulary completion. A summary with any outstanding error conditions is displayed before every prompt (see " { $link "ui.tools.error-list" } " for details)." "The graphical listener adds input history and word and vocabulary completion. A summary with any outstanding error conditions is displayed before every prompt (see " { $link "ui.tools.error-list" } " for details)."

View File

@ -222,7 +222,7 @@ M: listener-gadget focusable-child*
input>> dup popup>> or ; input>> dup popup>> or ;
: wait-for-listener ( listener -- ) : wait-for-listener ( listener -- )
input>> flag>> wait-for-flag ; input>> flag>> 5 seconds wait-for-flag-timeout ;
: listener-busy? ( listener -- ? ) : listener-busy? ( listener -- ? )
input>> interactor-busy? ; input>> interactor-busy? ;