celix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [celix] pnoltes commented on a change in pull request #203: Feature/osgi promise
Date Wed, 22 Apr 2020 06:48:09 GMT

pnoltes commented on a change in pull request #203:
URL: https://github.com/apache/celix/pull/203#discussion_r412714431



##########
File path: misc/experimental/promise/api/celix/Promise.h
##########
@@ -0,0 +1,512 @@
+/**
+ *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.
+ */
+
+#pragma once
+
+#include "celix/impl/SharedPromiseState.h"
+
+namespace celix {
+
+    /**
+     * A Promise of a value.
+     * <p>
+     * A Promise represents a future value. It handles the interactions for
+     * asynchronous processing. A {@link Deferred} object can be used to create a
+     * Promise and later resolve the Promise. A Promise is used by the caller of an
+     * asynchronous function to get the result or handle the error. The caller can
+     * either get a callback when the Promise is resolved with a value or an error,
+     * or the Promise can be used in chaining. In chaining, callbacks are provided
+     * that receive the resolved Promise, and a new Promise is generated that
+     * resolves based upon the result of a callback.
+     * <p>
+     * Both {@link #onResolve(Runnable) callbacks} and
+     * {@link #then(Success, Failure) chaining} can be repeated any number of times,
+     * even after the Promise has been resolved.
+     * <p>
+     * Example callback usage:
+     *
+     * <pre>
+     * celix::Promise&lt;std::string&gt; foo{};
+     * foo.onResolve([]{ std::cout << "resolved" << std::endl; });
+     * </pre>
+     *
+     *
+     * @tparam <T> The value type associated with this Promise.
+     * @ThreadSafe
+     */
+    template<typename T>
+    class Promise {
+    public:
+        using type = T;
+
+        explicit Promise(std::shared_ptr<celix::impl::SharedPromiseState<T>>
s);
+
+//        ~Promise() {
+//            //TODO maybe make a special detach call to state if the count is 1
+//            //state->detachIfNeeded(state); //create a callback with ref to self if
share_ptr count is 1
+//        }
+
+        /**
+         * Returns whether this Promise has been resolved.
+         *
+         * <p>
+         * This Promise may be successfully resolved or resolved with a failure.
+         *
+         * @return {@code true} if this Promise was resolved either successfully or
+         *         with a failure; {@code false} if this Promise is unresolved.
+         */
+        bool isDone() const;

Review comment:
       Yes, but the OSGi spec uses isDone. As it is now, I tried to follow the spec as close
as possible.




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message