aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2010-09-16 09:45:52 +1000
committerSteve Bennett <steveb@workware.net.au>2010-10-15 11:02:53 +1000
commit8977e7375635cfcc0d9a3461efba4f28268a4b89 (patch)
tree3bd2e9991ae5d04013cca82d5ab34b89d6d4f938
parent6c3dfbc2842400da314f139a043b908cda499839 (diff)
downloadjimtcl-8977e7375635cfcc0d9a3461efba4f28268a4b89.zip
jimtcl-8977e7375635cfcc0d9a3461efba4f28268a4b89.tar.gz
jimtcl-8977e7375635cfcc0d9a3461efba4f28268a4b89.tar.bz2
Implement 'after ms'
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r--jim-eventloop.c10
-rw-r--r--jim_tcl.txt8
2 files changed, 14 insertions, 4 deletions
diff --git a/jim-eventloop.c b/jim-eventloop.c
index ec8bfd1..ff94f50 100644
--- a/jim-eventloop.c
+++ b/jim-eventloop.c
@@ -467,8 +467,8 @@ static int JimELAfterCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{ INFO, CANCEL, RESTART, EXPIRE, CREATE };
int option = CREATE;
- if (argc < 3) {
- Jim_WrongNumArgs(interp, 1, argv, "<after milliseconds> script|cancel <id>");
+ if (argc < 2) {
+ Jim_WrongNumArgs(interp, 1, argv, "<after milliseconds> ?script|cancel <id>?");
return JIM_ERR;
}
if (Jim_GetWide(interp, argv[1], &ms) != JIM_OK) {
@@ -476,6 +476,12 @@ static int JimELAfterCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
return JIM_ERR;
}
}
+ else if (argc == 2) {
+ /* Simply a sleep */
+ sleep(ms / 1000);
+ usleep((ms % 1000) * 1000);
+ return JIM_OK;
+ }
switch (option) {
case CREATE:
Jim_IncrRefCount(argv[2]);
diff --git a/jim_tcl.txt b/jim_tcl.txt
index af16a55..9deb38a 100644
--- a/jim_tcl.txt
+++ b/jim_tcl.txt
@@ -79,6 +79,7 @@ Since v0.62:
17. 'exec' now sets $::errorCode, and catch sets opts(-errorcode) for exit status
18. Command pipelines via open "|..." are now supported
19. Add 'info references'
+20. Add support for 'after *ms*'
Since v0.61:
@@ -4058,15 +4059,18 @@ handler is removed.
Time-based execution is also available via the eventloop API.
++*after* 'time'+::
+ Sleeps for the given number of milliseconds. No events are processed during this time.
+
+*after* 'time script'+::
The script is executed after the given number of milliseconds have elapsed.
Returns an event id.
+*after cancel* 'id'+::
- Cancels an after event with the given event id.
+ Cancels an 'after' event with the given event id.
+*vwait* 'variable'+::
- A call to vwait is required to enter the eventloop. 'vwait' processes events until
+ A call to 'vwait' is required to enter the eventloop. 'vwait' processes events until
the named (global) variable changes. The variable need not exist beforehand.
If there are no event handlers defined, 'vwait' returns immediately.