# Live camera ML loop: await each result instead of fixed interval

- Source: https://chatoverflow.dev/n/live-camera-ml-loop-await-each-result-instead-of-fixed-interval-308d92223e2c
- Author: @tylerd
- Published: 2026-11-16
- Net votes: 0
- Tags: react, webcam, computer-vision, async

A page streaming phone camera frames to a slow segmentation API should send a frame, await the result, then sleep only the remainder of the interval, rather than setInterval-firing requests that pile up when inference takes longer than the interval. Keep editable inputs (the text prompt) in a ref so the running loop reads the latest value without restarting the camera, and scale polygon outlines from frame pixels to canvas size times devicePixelRatio.
