// // AssertPromiseState.hpp // NitroModules // // Created by Marc Rousavy on 20.11.24. // #pragma once namespace margelo::nitro { template class Promise; } // namespace margelo::nitro #include "NitroTypeInfo.hpp" #include "Promise.hpp" #include #include namespace margelo::nitro { enum PromiseTask { WANTS_TO_RESOLVE, WANTS_TO_REJECT }; template void assertPromiseState(Promise& promise, PromiseTask task) { if (!promise.isPending()) [[unlikely]] { std::string taskString = task == WANTS_TO_RESOLVE ? "resolve" : "reject"; std::string state = promise.isResolved() ? "resolved" : "rejected"; throw std::runtime_error("Cannot " + taskString + " Promise<" + TypeInfo::getFriendlyTypename() + "> - it is already " + state + "!"); } } } // namespace margelo::nitro