| 2039 | } |
| 2040 | |
| 2041 | Maybe<WorldServerThreadPtr> UniverseServer::triggerWorldCreation(WorldId const& worldId) { |
| 2042 | if (!m_worlds.contains(worldId)) { |
| 2043 | if (auto promise = makeWorldPromise(worldId)) { |
| 2044 | m_worlds.add(worldId, promise.take()); |
| 2045 | return {}; |
| 2046 | } else { |
| 2047 | return WorldServerThreadPtr(); |
| 2048 | } |
| 2049 | } else { |
| 2050 | auto& maybeWorldPromise = m_worlds.get(worldId); |
| 2051 | try { |
| 2052 | // If the promise is reset, this means that the promise threw an |
| 2053 | // exception, return nullptr to signify error. |
| 2054 | if (!maybeWorldPromise) |
| 2055 | return WorldServerThreadPtr(); |
| 2056 | |
| 2057 | if (!maybeWorldPromise->poll()) |
| 2058 | return {}; |
| 2059 | |
| 2060 | return maybeWorldPromise->get(); |
| 2061 | } catch (std::exception const& e) { |
| 2062 | maybeWorldPromise.reset(); |
| 2063 | Logger::error("UniverseServer: error during world create: {}", outputException(e, true)); |
| 2064 | worldDiedWithError(worldId); |
| 2065 | return WorldServerThreadPtr(); |
| 2066 | } |
| 2067 | } |
| 2068 | } |
| 2069 | |
| 2070 | Maybe<WorkerPoolPromise<WorldServerThreadPtr>> UniverseServer::makeWorldPromise(WorldId const& worldId) { |
| 2071 | if (auto celestialWorld = worldId.ptr<CelestialWorldId>()) |