2023-05-28 00:33:46 +03:00
|
|
|
// Copyright (c) 2019-2023 Alexander Medvednikov. All rights reserved.
|
|
|
|
// Use of this source code is governed by an MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
module coroutines
|
|
|
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
#flag -I @VEXEROOT/thirdparty/photon
|
|
|
|
#flag @VEXEROOT/thirdparty/photon/photonwrapper.so
|
|
|
|
|
|
|
|
#include "photonwrapper.h"
|
|
|
|
|
|
|
|
fn C.photon_init_default() int
|
2023-05-29 02:35:34 +03:00
|
|
|
fn C.photon_thread_create(f voidptr, arg voidptr)
|
2023-05-28 00:33:46 +03:00
|
|
|
fn C.photon_sleep_s(n int)
|
|
|
|
fn C.photon_sleep_ms(n int)
|
|
|
|
|
|
|
|
// sleep is coroutine-safe version of time.sleep()
|
|
|
|
pub fn sleep(duration time.Duration) {
|
|
|
|
C.photon_sleep_ms(duration.milliseconds())
|
|
|
|
}
|
2023-05-28 06:30:23 +03:00
|
|
|
|
2023-05-28 16:54:57 +03:00
|
|
|
fn init() {
|
2023-05-29 02:35:34 +03:00
|
|
|
ret := C.photon_init_default()
|
|
|
|
if ret < 0 {
|
|
|
|
panic('failed to initialize coroutines via photon (ret=${ret})')
|
|
|
|
}
|
2023-05-28 06:30:23 +03:00
|
|
|
}
|