1 /** 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef PLUGINS_ETS_RUNTIME_ETS_REMOTE_PROMISE_RESOLVER_H 17 #define PLUGINS_ETS_RUNTIME_ETS_REMOTE_PROMISE_RESOLVER_H 18 19 #include "plugins/ets/runtime/types/ets_object.h" 20 21 namespace ark::ets { 22 23 /// @brief interface of resolving/rejection of promise from remote side 24 class RemotePromiseResolver { 25 public: 26 enum class Action : uint8_t { RESOLVE, REJECT }; 27 28 RemotePromiseResolver() = default; 29 NO_COPY_SEMANTIC(RemotePromiseResolver); 30 NO_MOVE_SEMANTIC(RemotePromiseResolver); 31 virtual ~RemotePromiseResolver() = default; 32 33 /** 34 * @brief method should post to remote side callback to resolve/reject promise 35 * @param resolveValue: EtsObject to resolve/reject promise. If you want to reject promise, it should be exception 36 * with error description. If you want to resolve promise, you can use any object. 37 * @param action: use Action::Resolve if you want to resolve remote promise, otherwise use Action::Reject 38 */ 39 virtual void ResolveViaCallback(EtsObject *resolveValue, Action action) = 0; 40 41 /** 42 * @brief method should resolve/reject promise in current thread in please. Implement this method only if it's 43 * needed. 44 * @param resolveValue: EtsObject to resolve/reject promise. If you want to reject promise, it should be exception 45 * with error description. If you want to resolve promise, you can use any object. 46 * @param action: use Action::Resolve if you want to resolve remote promise, otherwise use Action::Reject 47 */ 48 virtual void ResolveInPlace(EtsObject *resolveValue, Action action) = 0; 49 }; 50 51 } // namespace ark::ets 52 53 #endif // PLUGINS_ETS_RUNTIME_ETS_REMOTE_PROMISE_RESOLVER_H