mirror of
https://github.com/ZmnSCPxj/clboss.git
synced 2026-08-13 12:33:20 +02:00
24 lines
574 B
C++
24 lines
574 B
C++
|
|
#undef NDEBUG
|
||
|
|
#include"Ev/coroutine.hpp"
|
||
|
|
#include"Ev/start.hpp"
|
||
|
|
#include<assert.h>
|
||
|
|
|
||
|
|
/* A coroutine that completes before the caller attaches to the returned Io. */
|
||
|
|
Ev::Io<int> already_finished() {
|
||
|
|
co_return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
int main() {
|
||
|
|
auto io = already_finished();
|
||
|
|
|
||
|
|
/* Simulate the libev idle handler running before anyone consumes the Io.
|
||
|
|
* With the current coroutine cleanup scheduling this destroys the promise
|
||
|
|
* early and the subsequent run would use freed memory.
|
||
|
|
*/
|
||
|
|
Ev::coroutine::do_cleaning_as_scheduled();
|
||
|
|
|
||
|
|
auto ec = Ev::start(io);
|
||
|
|
assert(ec == 0);
|
||
|
|
return 0;
|
||
|
|
}
|