7

promises in JavaScript have really spoiled me

it's the most optimal way to do async without leaving much on the table

there's a promises library in rust and the guy who wrote it says it sucks because it spawns new thread every time you execute a bunch of promises

and I finally, through my fogged brain, managed to get the bright idea to write what I want to make in rust in JavaScript and holy hell it's sexy to work with promises. there's no performance left on the table. you do things as fast as possible

but if I take this JavaScript usability code I made and make it possible syntax-wise in rust I don't see how I would be able to do it without starting new operating system threads every time I execute any promises (or set)

I can take the overhead hit but this sounds retarded

and this isn't even touching upon how in rust everything needs to have a predetermined data type. so you can do lambdas and capture variables and send in variables into a thread that way, but to return the return object must be a consistent type (synchronizing the order data was sent in to the data sent out aside, haven't written that yet should be fine though)

which is fine if you are making a threadpool and it'll all be returning one data type
but this means you can't reuse a threadpool you made elsewhere in the program

the only thing that could fix async is to literally be compiler-enabled. it would have to work like generics and automatically make an enum of every type that can return, and only then could you re-use the threadpool

Comments
  • 3
    async/await is the most optimal way to do async (if it’s built into the language and is not some half assed 3rd party lib)!
  • 0
    @Demolishun yes, Swift has that. It’s called plugins.
    Not sure about other languages.
  • 0
    @Demolishun some browsers run tabs in their own dedicated child processes.
  • 0
    @retoor it "kind of" does for webworkers, but that's about it.
  • 0
    btw, @jestdotty, maybe scheme continuations is what you're after. I'm not sure, but maybe Rusty's macro systems is enough to implement it
  • 0
    @retoor is that for javascript?
  • 0
    @jestdotty hmmm 🤔 maybe it'd be expensive learning scheme just for that.

    You could use fibers then!

    They're already made available by the kernel and cost very little.

    ---

    there's also a nice and tiny fibers implementation already done by Calvin Rose over at janet-lang.

    https://github.com/janet-lang/...

    Your C Is better than mine, I bet you could make that Rust in no time
  • 0
    @retoor so what you're saying is every browser is carrying around a c compiler bundled with it?
  • 1
    @Wisecrack nop, just a JavaScript jit compiler
  • 0
    I agree. Promises are a really excellent backwards compatible solution.

    However, they don’t have anything to do with performance whatsoever
  • 0
    @retoor "yes also rust, not by much."

    Like removing the guardrails from a nine hundred foot cliff face tourist attraction.

    If you want to get really close to the edge, it is the only way to do it.
  • 2
    @Wisecrack honestly, if you reaaaaally wanna go bareback, look no further than Zig. I can't, it's too much for me
  • 3
    @kobenz I like zig. I could make some real monstrosities in it.
Add Comment