java – Convert a callback based flow to async iterable

Let’s say I have some event-based flow, for example a “read only” websocket. Normally you set the “onmessage” callback to deal with incoming messages.
Is there some way to access the messages in an async iterator? My goal is to have

async () => {
    for await (const message of SOMETHING(new WebSocket('...'))) {
        // message is the content of the callback
    }
};

I have toyed with promises and queues, but I couldn’t find a way to convert a callback (called multiple times) to an (async-) iterator