Re:Async Queue – One of My Favorite Programming Interviews (...
by gloosx on Monday July 07, 2025 @08:24AM
(#44489625)
The proper implementation looks kinda bulky to me. Are you not allowed to use promises? Feels more like a naive solution for anyone who has few months of experience with javascript or is it cheating?
[ Parent
| on HN ]
Re:Async Queue – One of My Favorite Programming Interviews (...
by a-priori on Monday July 07, 2025 @11:34AM
(#44491439)
You'll need to flatten the promise periodically if you use this approach, otherwise your performance will degrade a bit each time you enqueue something.
Re:Async Queue – One of My Favorite Programming Interviews (...
by dbetteridge on Monday July 07, 2025 @10:47AM
(#44490939)
Readability over brevity for maintainable code (I know an interview doesn't require this, but I look for it)
While this works, it's not exactly intuitive.
Re:Async Queue – One of My Favorite Programming Interviews (...
by gloosx on Monday July 07, 2025 @11:00AM
(#44491091)
In context of JS this kind of promisified async code is intuitive and this pattern is quite common in various projects and libraries, but the solution in C-like pseudocode of course looks more readable for general programming public.
Re:Async Queue – One of My Favorite Programming Interviews (...
by no_wizard on Monday July 07, 2025 @12:41PM
(#44492125)
I agree, this seems incredibly readable to me, though I work in TypeScript / JavaScript all day and know the language and its patterns very well.
Re:Async Queue – One of My Favorite Programming Interviews (...
by mind-blight on Monday July 07, 2025 @08:44AM
(#44489810)
I actually tried to use this pattern to make an audio controller interface much nicer. If you get a long enough queue, you'll start to run into errors (I'm forgetting the exact message, but it was similar to a maximum recursion depth)
Re:Async Queue – One of My Favorite Programming Interviews (...
by gloosx on Monday July 07, 2025 @10:51AM
(#44490998)
This most likely happened because you had a queue operation which started another queue operation so a recursion was created which consumed every bit of memory it had available.
Re:Async Queue – One of My Favorite Programming Interviews (...
by MrDarcy on Monday July 07, 2025 @09:06AM
(#44489995)
I believe you that this works, but I can’t easily read or comprehend it without considerable effort, so I’d grade it below a solution I could.
Re:Async Queue – One of My Favorite Programming Interviews (...
by gloosx on Monday July 07, 2025 @10:56AM
(#44491061)
If this is given in Javascript, I'd rate the promise solution higher since a Javascript job involves a ton of promisified async code like this. If this is given in C or pseudo-code, then for sure a good ol stack+flag+loop is looking good enough.
Re:Async Queue – One of My Favorite Programming Interviews (...
by craftkiller on Wednesday July 09, 2025 @01:05PM
(#44512418)
> without considerable effort
Are you sure? I'm not a javascript programmer and it took less than 2 minutes to comprehend. If you think this takes considerable effort to comprehend then I don't think you actually tried.
Re:Async Queue – One of My Favorite Programming Interviews (...
by damidekronik on Monday July 07, 2025 @08:50AM
(#44489850)
And then once The Anyone gets few more years of experience they revert back to the bulky one.