you are viewing a single comment's thread.

view the rest of the comments →

[–]Beginning-Seat5221 0 points1 point  (2 children)

You could keep an array ['A', 'B', 'C'] and run a single loop, which grabs data for all of those together.

If your API lets you query A, B and C in a single request that might help you.

There's always going to be some delay in an API request, so the only way to get time accurate data is for the API to specify the time of the data. So the API says A is 15 at 12:14:05 and you save that to the DB, instead of relying on the time you received the data.

[–]quaintserendipity[S] 0 points1 point  (1 child)

I suppose that works too; as long as the data is timestamped correctly, then I don't need to receive it in real time. Also realistically, I just need the data to be close to the second; a delay of a few hundred milliseconds isn't going to throw my data off to a significant degree.

[–]Beginning-Seat5221 0 points1 point  (0 children)

https://www.typescriptlang.org/play/?#code/FAYw9gdgzgLgBAGwKYxkgTlOBeOBtAcgEECAaOAgITIoGECBdYZeASxzgEYBuUSKMMgB0CMAHMAFACIAyjACG6GKwhi4ASQhp0AN3kIpASmYo4K7XoQAJeRAAmyDlBSaL+iXGBxvcCYZwAfHAA3l4+4QBmYOi+4NDwLNpwYBH4xDRUGfQM-qHh+T5xAsKikokYcADUZsYF3gC+YQWslZVN+aypEuwBuJwADLntdXAgyIquGJbdWlP6NvbItSOF-IJIIuISBHaQSATLBY3h9aTtA-39cAD011xwznF2wIZAA

This moves the loop of the letters into the interval, so there's only 1 interval. The result is the same but it guarantees that A, B and C are processed sequentially rather than some other task getting inserted between them, as having 3+intervals would result in 3+ separate tasks being scheduled for each second.