Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions doc/sphinx_source/using/tcl-commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2359,6 +2359,46 @@ utimer <seconds> <tcl-command> [count [timerName]]

Module: core

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
timerexistsname <timerName>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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 <timerName>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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
^^^^^^
Expand Down
25 changes: 25 additions & 0 deletions src/tclmisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tcl_AppendResult() is deprecated. Use Tcl_SetResult() if you can. You could do a one-liner, something like:

Tcl_SetResult(interp, find_timer(timer, argv[1]) ? "1" : "0", TCL_STATIC);

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
{
Expand Down Expand Up @@ -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},
Expand Down
Loading