diff --git a/doc/sphinx_source/using/tcl-commands.rst b/doc/sphinx_source/using/tcl-commands.rst index 0fbbecb6d..594195078 100644 --- a/doc/sphinx_source/using/tcl-commands.rst +++ b/doc/sphinx_source/using/tcl-commands.rst @@ -2359,6 +2359,46 @@ utimer [count [timerName]] Module: core +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +timerexistsname +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + Description: Checks if a named minutely timer exists. + + Returns: + - "1" if the timer exists + - "0" if the timer doesn't exist + + Examples: + ```tcl + # Check timer existence + if {[timerexistsname "mytimer"]} { + putlog "Timer 'mytimer' exists" + } + ``` + + Module: core + +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +utimerexistsname +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + Description: Checks if a named secondly timer (utimer) exists. + + Returns: + - "1" if the utimer exists + - "0" if the utimer doesn't exist + + Examples: + ```tcl + # Check utimer existence + if {![utimerexistsname "myutimer"]} { + utimer 30 [list do_something] 0 "myutimer" + } + ``` + + Module: core + ^^^^^^ timers ^^^^^^ diff --git a/src/tclmisc.c b/src/tclmisc.c index 84af8e847..4226dc019 100644 --- a/src/tclmisc.c +++ b/src/tclmisc.c @@ -303,6 +303,29 @@ static int tcl_utimer STDVAR Tcl_AppendResult(irp, x, NULL); return TCL_OK; } +static int tcl_timerexistsname STDVAR +{ + BADARGS(2, 2, " timerName"); + + if (find_timer(timer, argv[1])) { + Tcl_SetResult(irp, "1", TCL_STATIC); + } else { + Tcl_SetResult(irp, "0", TCL_STATIC); + } + return TCL_OK; +} + +static int tcl_utimerexistsname STDVAR +{ + BADARGS(2, 2, " utimerName"); + + if (find_timer(utimer, argv[1])) { + Tcl_SetResult(irp, "1", TCL_STATIC); + } else { + Tcl_SetResult(irp, "0", TCL_STATIC); + } + return TCL_OK; +} static int tcl_killtimer STDVAR { @@ -822,6 +845,8 @@ tcl_cmds tclmisc_cmds[] = { {"putloglev", tcl_putloglev}, {"timer", tcl_timer}, {"utimer", tcl_utimer}, + {"timerexistsname", tcl_timerexistsname}, + {"utimerexistsname", tcl_utimerexistsname}, {"killtimer", tcl_killtimer}, {"killutimer", tcl_killutimer}, {"timers", tcl_timers},