regl-project / regl

👑 Functional WebGL
https://regl-project.github.io/
MIT License
5.22k stars 322 forks source link

[Feature Request] Asynchronous DrawCommand #652

Open nandin-borjigin opened 2 years ago

nandin-borjigin commented 2 years ago

regl is an awesome library to use! I really like it!

For my use case, I need to do some asynchronous staff in the command body function and wait for that asynchronous operation outside of the command.

regl(config)(async () => something());

// need to wait for something to finish

For now I'm utilizing p-defer, but I think if REGL.DrawCommand could forward the return value of its body, it would help a lot.

// for now
const deferred = defer();
regl(config)(async () => {
  await something();
  deferred.resolve();
})

await deferred.promise;
// desired

await regl(config)(() => something());