westonpace commented on a change in pull request #10968: URL: https://github.com/apache/arrow/pull/10968#discussion_r697666997
########## File path: cpp/src/arrow/util/async_nursery.cc ########## @@ -0,0 +1,130 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "arrow/util/async_nursery.h" + +#include "arrow/util/logging.h" + +namespace arrow { +namespace util { + +AsyncCloseable::AsyncCloseable() = default; +AsyncCloseable::AsyncCloseable(AsyncCloseable* parent) { + parent->AddDependentTask(OnClosed()); +} + +AsyncCloseable::~AsyncCloseable() { + // FIXME - Would be awesome if there were a way to enforce this at compile time + DCHECK_NE(nursery_, nullptr) << "An AsyncCloseable must be created with a nursery " + "using MakeSharedCloseable or MakeUniqueCloseable"; +} + +const Future<>& AsyncCloseable::OnClosed() { + // Lazily create the future to save effort if we don't need it + if (!on_closed_.is_valid()) { + on_closed_ = Future<>::Make(); + } Review comment: I think you're right about the danger. It is used elsewhere at the moment in the dataset writer PR (https://github.com/apache/arrow/pull/10955/files#diff-387ad04c2450a38044e667e07183b8265866cb3736d10acdce137c2b83737b16R345-R346). I use it decrement the number of open writers when the file has finished writing. So I just changed it so we always create the future. It was a bit of a premature optimization anyways. ########## File path: cpp/src/arrow/util/async_nursery.h ########## @@ -0,0 +1,157 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#ifndef ARROW_ASYNC_NURSERY_H Review comment: Switched to this. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org