Skip to content

Waiting on a file descriptor without blocking the event loop #1320

Answered by bakpakin
bitcompost asked this question in Q&A
Discussion options

You must be logged in to vote

As far as the original issue (100% cpu issue aside), the new code to do this in C is as follows:

static void callback(JanetFiber *fiber, JanetAsyncEvent event) {
    switch(event) {
        default:
            return;
        case JANET_ASYNC_EVENT_READ:
        case JANET_ASYNC_EVENT_HUP:
        case JANET_ASYNC_EVENT_ERR:
            break;
    }
    janet_schedule(fiber, janet_wrap_nil());
    janet_async_end(fiber);
}

JANET_FN(cfun_wayland_wait,
        "(wayland/wait stream)",
        "Wait a stream to be ready for reading, but do not actually read from the stream.") {
    janet_fixarity(argc, 1);
    JanetStream *stream = janet_getabstract(argv, 0, &janet_stream_type);
    // Opt…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
3 replies
@bitcompost
Comment options

@bitcompost
Comment options

@bakpakin
Comment options

Comment options

You must be logged in to vote
2 replies
@bitcompost
Comment options

@bakpakin
Comment options

Answer selected by bitcompost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants