diff options
author | cjihrig <cjihrig@gmail.com> | 2019-12-04 07:02:49 +0300 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2019-12-09 12:23:12 +0300 |
commit | dc69cbeb0532b3d4d86f37c9f06abe642714fba6 (patch) | |
tree | 59712ade4b15f9385ab43d6189862bc8436eb659 /src | |
parent | d4aa656d575b0c1c6da3b8dc2ae5f64ff410648d (diff) |
util: add internal sleep() function
PR-URL: https://github.com/nodejs/node/pull/30787
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/node_util.cc | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/node_util.cc b/src/node_util.cc index 07a7b69dbd9..b9553eaaa67 100644 --- a/src/node_util.cc +++ b/src/node_util.cc @@ -169,6 +169,12 @@ static void SetHiddenValue(const FunctionCallbackInfo<Value>& args) { args.GetReturnValue().Set(maybe_value.FromJust()); } +static void Sleep(const FunctionCallbackInfo<Value>& args) { + CHECK(args[0]->IsUint32()); + uint32_t msec = args[0].As<Uint32>()->Value(); + uv_sleep(msec); +} + void ArrayBufferViewHasBuffer(const FunctionCallbackInfo<Value>& args) { CHECK(args[0]->IsArrayBufferView()); args.GetReturnValue().Set(args[0].As<ArrayBufferView>()->HasBuffer()); @@ -290,6 +296,7 @@ void Initialize(Local<Object> target, env->SetMethodNoSideEffect(target, "getOwnNonIndexProperties", GetOwnNonIndexProperties); env->SetMethodNoSideEffect(target, "getConstructorName", GetConstructorName); + env->SetMethod(target, "sleep", Sleep); env->SetMethod(target, "arrayBufferViewHasBuffer", ArrayBufferViewHasBuffer); Local<Object> constants = Object::New(env->isolate()); |