0
Get value from a data stream
i have a data stream that delivers new values every few seconds. The values then populate specfic areas of a web page. Can you indicate a good way to compare these values? Webdriver would be a bit to slow here since by the time you switch read a value it may be that the actual value from the data stream is different
1 ответ
+ 1
Could you be more specific about the source / comparison?
Websockets will work in workers I believe. I have workers figured out so I could test that tomorrow... This addresses temporal issues because sockets are live + threads run simultaneously. Workers can message each other, so once they grab a value it's free to change for a new worker.
There's Fetch, which is also asynchronous, but I kindof think you either want element.onchange() or a DOM hook: Mutation / Observer events:
https://code.sololearn.com/WHpWYpR5FWwi/?ref=app
That codes fires the next event by changing color. In this API, you can hook the DOM for just about every attribute/element change...and the event fires when it happens vs. having to use timeouts.
Line 41:
function setObserver(){
observer=new WebKitMutationObserver(
function(mutations) {
// displayMutations(); // see warning in function!
setTimeout(setNewColor, pacing); // mutate [stream in]
}
);
I'd use mutations to record a data item + timestamp, and then sort by arrival time... if your stream changes the DOM. if that's not right more info on the comparison itself may help.