zhanzhenzhen / futurescript

A future-style language.
https://futurescript.org/
Other
43 stars 3 forks source link

Better asynch support #29

Closed kristianmandrup closed 7 years ago

kristianmandrup commented 7 years ago

For async I suggest you have a look at rq by Douglas Crawford as presented in this video

This elegantly solves complex async flows without promises and try/catch/finally :)

respond = RQ.fallback([
    RQ.sequence([
        getId,
        getPreference,
        RQ.parallel([
            getNav,
            RQ.race([
                getAd(adnet.klikHaus),
                getAd(adnet.inUFace),
                getAd(adnet.trackPipe)
            ]),
            RQ.fallback([
                fetch("weather", localCache),
                fetch("weather", localDB),
                fetch("weather", remoteDB)
            ]),
            getMessageOfTheDay
        ], [
            getHoroscope,
            getGossip
        ], 50),
        construct(['nav', 'ads', 'weather', 'message', 'horoscope', 'gossip']),
        buildPage
    ], 100),
    planB
]};

Would it make sense to incorporate this directly!?

x: ~.. [
      ~|| [
        getNav
        ~1 [
          getAd adnet.klikHaus
          getAd adnet.inUFace
        ] 
        ~:o [
          rescue
        ]
      ]
    ]

I know this is likely too specific for your taste? Would love to learn how to add my own additions like this! Cheers!

kristianmandrup commented 7 years ago

I guess this would require "simply" inserting a ~ rule for round 1 in lex-core.js with a specific Stream class with that symbol identifier, then in a later round replacing that class/property combi with a specific function call? Pretty neat :)

zhanzhenzhen commented 7 years ago

FutureScript already has 'wait, that's almost equivalent to ECMAScript async and await. It returns a promise.