From 5207dec0175de92116262e8382d6ac57def3a203 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Mon, 15 Jul 2019 22:17:45 +0200 Subject: src: allow generic C++ callables in SetImmediate() Modify the native `SetImmediate()` functions to take generic C++ callables as arguments. This makes passing arguments to the callback easier, and in particular, it allows passing `std::unique_ptr`s directly, which in turn makes sure that the data they point to is deleted if the `Environment` is torn down before the callback can run. PR-URL: https://github.com/nodejs/node/pull/28704 Reviewed-By: James M Snell --- src/cares_wrap.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/cares_wrap.cc') diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 85d0fdbde64..96062cb4819 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -690,9 +690,9 @@ class QueryWrap : public AsyncWrap { } void QueueResponseCallback(int status) { - env()->SetImmediate([](Environment*, void* data) { - static_cast(data)->AfterResponse(); - }, this, object()); + env()->SetImmediate([this](Environment*) { + AfterResponse(); + }, object()); channel_->set_query_last_ok(status != ARES_ECONNREFUSED); channel_->ModifyActivityQueryCount(-1); -- cgit v1.2.3