| 125 | //============================================================================= |
| 126 | |
| 127 | class TaskCoroutineWasm : public ICoroutineTask { |
| 128 | public: |
| 129 | static TaskCoroutinePtr create(fl::string name, |
| 130 | TaskFunction function, |
| 131 | size_t stack_size = 4096, |
| 132 | u8 priority = 5) FL_NOEXCEPT { |
| 133 | auto* ctx = CoroutineContext::create(fl::move(function), stack_size); |
| 134 | if (!ctx) { |
| 135 | FL_WARN("TaskCoroutineWasm: Failed to create context for '" |
| 136 | << name << "'"); |
| 137 | return nullptr; |
| 138 | } |
| 139 | |
| 140 | TaskCoroutinePtr task(new TaskCoroutineWasm()) FL_NOEXCEPT; // ok bare allocation |
| 141 | auto* impl = static_cast<TaskCoroutineWasm*>(task.get()); |
| 142 | impl->mName = fl::move(name); |
| 143 | impl->mContext.reset(ctx); |
| 144 | |
| 145 | // Register with the global runner |
| 146 | CoroutineRunner::instance().enqueue(ctx); |
| 147 | |
| 148 | return task; |
| 149 | } |
| 150 | |
| 151 | ~TaskCoroutineWasm() override { stop(); } |
| 152 | |
| 153 | void stop() FL_NOEXCEPT override { |
| 154 | if (!mContext) return; |
| 155 | mContext->stop_and_complete(); |
| 156 | CoroutineRunner::instance().remove(mContext.get()); |
| 157 | } |
| 158 | |
| 159 | bool isRunning() const FL_NOEXCEPT override { |
| 160 | if (!mContext) return false; |
| 161 | return !mContext->is_completed(); |
| 162 | } |
| 163 | |
| 164 | private: |
| 165 | TaskCoroutineWasm() = default; |
| 166 | |
| 167 | fl::string mName; |
| 168 | fl::unique_ptr<CoroutineContext> mContext; |
| 169 | }; |
| 170 | |
| 171 | //============================================================================= |
| 172 | // Factory function |
nothing calls this directly
no test coverage detected