From c9673e08b3ca9230c492596ecb805210c49265f7 Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Wed, 8 Aug 2012 15:33:11 +0200 Subject: [PATCH] added internal.wait --- lib/V8/v8-utils.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/V8/v8-utils.cpp b/lib/V8/v8-utils.cpp index 6f1bbcbb7a..b270ff036a 100644 --- a/lib/V8/v8-utils.cpp +++ b/lib/V8/v8-utils.cpp @@ -1103,6 +1103,38 @@ static v8::Handle JS_Time (v8::Arguments const& argv) { return scope.Close(v8::Number::New(TRI_microtime())); } +//////////////////////////////////////////////////////////////////////////////// +/// @brief returns the current time +/// +/// @FUN{internal.wait()} +/// +/// Wait for , call the garbage collection. +//////////////////////////////////////////////////////////////////////////////// + +static v8::Handle JS_Wait (v8::Arguments const& argv) { + v8::HandleScope scope; + + // extract arguments + if (argv.Length() != 1) { + return scope.Close(v8::ThrowException(v8::String::New("usage: wait()"))); + } + + double n = TRI_ObjectToDouble(argv[0]); + double until = TRI_microtime() + n; + + while(! v8::V8::IdleNotification()) { + } + + while (TRI_microtime() < until) { + while(! v8::V8::IdleNotification()) { + } + + usleep(100); + } + + return scope.Close(v8::Undefined()); +} + //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// @@ -1506,6 +1538,10 @@ void TRI_InitV8Utils (v8::Handle context, string const& path) { v8::FunctionTemplate::New(JS_Time)->GetFunction(), v8::ReadOnly); + context->Global()->Set(v8::String::New("SYS_WAIT"), + v8::FunctionTemplate::New(JS_Wait)->GetFunction(), + v8::ReadOnly); + // ............................................................................. // create the global variables // .............................................................................