admin管理员组文章数量:1327750
I've created a demo for RxJS scan()
method but unfortunately my timer doesn't work properly and I get this error: Timer 'myTimer' does not exist
console.time('myTimer');
let source = Rx.Observable
.interval(100) // interval starts from 0
.take(4)
.scan((acc, val) => acc + val);
source.subscribe((value) => {
console.timeEnd('myTimer');
console.log('in next. Value: ', value);
});
Here is a demo in JSBin.
Here is a source that I Copy code from that.
How can fix that issue?
I've created a demo for RxJS scan()
method but unfortunately my timer doesn't work properly and I get this error: Timer 'myTimer' does not exist
console.time('myTimer');
let source = Rx.Observable
.interval(100) // interval starts from 0
.take(4)
.scan((acc, val) => acc + val);
source.subscribe((value) => {
console.timeEnd('myTimer');
console.log('in next. Value: ', value);
});
Here is a demo in JSBin.
Here is a source that I Copy code from that.
How can fix that issue?
Share Improve this question edited Mar 24, 2023 at 17:52 mikemaccana 124k110 gold badges430 silver badges533 bronze badges asked May 25, 2018 at 8:10 user4661780user4661780 2-
2
Hi! The way SO works, your whole question (including any necessary code) has to be in your question, not just linked. Two reasons: People shouldn't have to go off-site to help you; and links rot, making the question and its answers useless to people in the future. Please put a minimal reproducible example in the question, ideally a runnable one using Stack Snippets (the
[<>]
toolbar button; here's how to do one). More: How do I ask a good question? – T.J. Crowder Commented May 25, 2018 at 8:12 - 3 How does the title "Console.timer() dose not exist" relate to the error message "Timer 'myTimer' does not exist"? – T.J. Crowder Commented May 25, 2018 at 8:13
2 Answers
Reset to default 5You may be calling timeEnd()
multiple times.
Once you've stopped the timer with console.timeEnd("name")
it no longer exists when using chrome.
console.time("myTimer");
for(var i=0;i<10000;i++){
}
console.timeEnd("myTimer"); // works
console.timeEnd("myTimer"); // displays an error (in chrome only)
Which is pretty much what your code is doing. The first time subscribe
is called your timer outputs the amount of time since it ws started. On the 3 subsequent calls it does not work.
This behaviour is specific to Chrome, it works how you expect in both IE & Firefox.
Just add
console.time("myTimer")
at the start of your function in which you are using .timeEnd
本文标签: javascriptWhat is causing 39myTimer does not exist39 error in consoletimeEnd()Stack Overflow
版权声明:本文标题:javascript - What is causing 'myTimer does not exist' error in console.timeEnd()? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742229083a2436881.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论