@@ -1572,19 +1572,22 @@ void function_node_interface_destroy(function func, function_impl impl)
15721572 return ;
15731573 }
15741574
1575- loader_impl_node node_impl = node_func->node_impl ;
1576- loader_impl_async_func_destroy_safe_type func_destroy_safe (node_impl, node_func);
1577-
1578- /* Check if we are in the JavaScript thread */
1579- if (node_impl->js_thread_id == std::this_thread::get_id ())
1580- {
1581- /* We are already in the V8 thread, we can call safely */
1582- node_loader_impl_func_destroy_safe (node_impl->env , &func_destroy_safe);
1583- }
1584- else
1575+ if (loader_is_destroyed (node_func->node_impl ->impl ) != 0 )
15851576 {
1586- /* Submit the task to the async queue */
1587- loader_impl_threadsafe_invoke_type<loader_impl_async_func_destroy_safe_type> invoke (node_impl->threadsafe_func_destroy , func_destroy_safe);
1577+ loader_impl_node node_impl = node_func->node_impl ;
1578+ loader_impl_async_func_destroy_safe_type func_destroy_safe (node_impl, node_func);
1579+
1580+ /* Check if we are in the JavaScript thread */
1581+ if (node_impl->js_thread_id == std::this_thread::get_id ())
1582+ {
1583+ /* We are already in the V8 thread, we can call safely */
1584+ node_loader_impl_func_destroy_safe (node_impl->env , &func_destroy_safe);
1585+ }
1586+ else
1587+ {
1588+ /* Submit the task to the async queue */
1589+ loader_impl_threadsafe_invoke_type<loader_impl_async_func_destroy_safe_type> invoke (node_impl->threadsafe_func_destroy , func_destroy_safe);
1590+ }
15881591 }
15891592
15901593 /* Free node function arguments */
0 commit comments