question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why does zipping with periodic() hangs?

See original GitHub issue

Summary

I want to print a stream of increasing numbers every 1s, but the code below hangs Node.js forever:

// test.js
const { iterate, periodic } = require('most')

iterate(x => x + 1, 0)
  .take(10)
  .zip(x => x, periodic(1000))
  .forEach(x => console.log(x))

while this

iterate(x => x + 1, 0)
  .take(10)
  .forEach(x => console.log(x))

terminates as expected.

Expected result

Expected output would be:

$ node test.js
0
1 # after 1s
2 # after 2s
...

Actual Result

$ node test.js
0 # <- hangs here and CPU usage goes up

Versions

  • most.js: 1.5.0

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
briancavaliercommented, Jul 31, 2017

Hi @iwinux, thanks for reporting this. The sample code to reproduce was very helpful! It appears to be a regression in take introduced in #428 (technically, a regression in slice, on which take is based). The regression is causing iterate to run forever, and continuously preempt the periodic task.

The reason it manifests with zip is that zip has to buffer the very fast iterate events, while waiting for corresponding periodic events, which never occur due to the preemption mentioned above.

The fix is relatively simple, and I should have time tonight to create a branch so you can try it.

If you’re indeed blocked by needing a periodic counter, then this will work and hopefully unblock you until the fix is ready:

periodic(1000)
  .slice(1, 10)
  .scan((x, _) => x + 1, 0)
  .forEach(x => console.log(x))

I’m guessing your example is a simplified version of a real use case, so this may not help, but figured it was worth a shot. Cheers!

1reaction
briancavaliercommented, Aug 1, 2017

@iwinux There’s a candidate fix in #467 (fix-466 branch). Could you give it a try and let us know if it works for you?

UPDATE: There’s a slightly cleaner fix in #468 (fix-466-2 branch). Please give that one a try and let us know. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Phone get hanged while unzipping a file in android
If the app freezes it's usually because you do too much computation on the main/UI thread (note that runOnUiThread() does exactly this).
Read more >
Windows 11 File Explorer repeatedly hangs when there is a ...
Windows 11 File Explorer repeatedly hangs when there is a zip file in the folder being viewed. It's a new laptop, was ok...
Read more >
Hooke's law - xaktly.com
Hooke's law says that the force produced by a spring is proportional to the displacement (linear amount of stretching or compressing) of that...
Read more >
Compress hangs when compressing folders w…
Compress hangs when compressing folders with dot underscore (._*) files. ... And then try to compress folder "a" on the desktop. It will...
Read more >
How to Fix Google Drive Zipping Files Stuck | 5 Ways + 2 Tips
Here are 5 solutions to Google Drive zipping 1 file stuck. Let's solve the issue now.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found