MCPcopy Create free account
hub / github.com/FastLED/FastLED / TaskCoroutineWasm

Class TaskCoroutineWasm

src/platforms/wasm/coroutine_runtime_wasm.impl.hpp:127–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125//=============================================================================
126
127class TaskCoroutineWasm : public ICoroutineTask {
128public:
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
164private:
165 TaskCoroutineWasm() = default;
166
167 fl::string mName;
168 fl::unique_ptr<CoroutineContext> mContext;
169};
170
171//=============================================================================
172// Factory function

Callers

nothing calls this directly

Calls 4

stop_and_completeMethod · 0.80
removeMethod · 0.45
getMethod · 0.45
is_completedMethod · 0.45

Tested by

no test coverage detected