21
hexc
6y

Lol is this even JavaScript anymore?!?

Comments
  • 4
    OOP much?
  • 2
    @Stocken honestly I just wanted to see how awkward it would be to use non blocking fs calls to read in the full file structure starting from a specified "root". I wanted to do everything in one shot, and I'll probably refactor it later so it's possible, but yeah, kinda cool to asynchronously/recursivly traverse a file system.
  • 3
    @hexc Understandable, been working with a similar type of code before, but if it works, don't change it!
  • 1
    @Stocken it works but more of a proof of concept at the moment, going to clean it up a lot, that just my quick/dirty pass at it
  • 2
    Js is evolving to be better and avoid much of the old problems.
  • 1
    Beautify it dud
  • 14
    Async was made to avoid pyramid sir
  • 2
    @devTea like I said I'll fix it tomorrow tired after ATM lol don't code tired it's not good for anyone
  • 2
    Why are there nested promises
  • 1
    I never really understood Promise or the concept of it.
  • 2
    Nicely formatted, I'd say...
  • 1
  • 1
    @nothappy it's a better way of doing callbacks. I believe that's the simplest expo.
  • 1
    Ever heard of if/else?
    Also wth is that semicolon at the beginning of the line? Put it on the end or just dont put it anywhere
  • 1
    @WIPocket semicolons are only actually needed in the one spot I put it, sure it could be on the previous line but since it's only needed when the next line is a void self invoking function, I just do it there
  • 1
    @norman70688 I was going to use promisify to wrap the fs functions so it wont be so ugly, but basically that will do the same thing as what's seen here. As far as the promises, being necessary, I need a way to "wait" for all the files to be found and stat'ed, but I want all the files to be found asynchronously, so by using promises recursivly than waiting for all active promises to be fulfilled, I achieve what I was trying to. That said maybe there are other nicer ways, which I'll explore but I was crazy tired when I wrote that, and this was posted as a joke(though it's functional).
  • 0
    This is just noob coding . Should give async/await a try.
  • 0
    @hexc Oh I see the () now...
    I usualy use semicolons so I dont rly have to worry about that...
    But still. That justs looks dumb
  • 0
    @code-freak problem is you can't async/await callback code unless you wrap it in a promise. You might notice I am using async await at the top level because that returns a promise. Also ide argue that most "noobs" wouldn't know what half this code does and why it works. As I've said before, it needs to be refactored/cleaned up, but the concept behind it(non blocking asyc recursion) is also something a noob would most likely not understand.
  • 0
    To be honest, there are better ways to do this, and I remember nodejs having promises support for the fs methods. I also don't see the point of having an async function without any awaits.
  • 0
    @MonkeyParade this is old and it's been cleaned up since than, had written it when I was tired af...
Add Comment