3 ms·
That's nice and all. But then you have abominations like this: state .db .send(Queries::GetTopTenHottestYears) .from_err()
by Spiritus 8y ago
That's nice and all. But then you have abominations like this:
state
.db
.send(Queries::GetTopTenHottestYears)
.from_err()
.and_then(move |res| {
result.push(res.unwrap());
state
.db
.send(Queries::GetTopTenColdestYears)
.from_err()
.and_then(move |res| {
result.push(res.unwrap());
state
.db
.send(Queries::GetTopTenHottestMonths)
.from_err()
.and_then(move |res| {
result.push(res.unwrap());
state
.db
.send(Queries::GetTopTenColdestMonths)
.from_err()
.and_then(move |res| {
result.push(res.unwrap());
fut_ok(result)
})
})
})
})
.and_then(|res| Ok(HttpResponse::Ok().json(res)))
.responder()
https://github.com/actix/examples/blob/master/async_db/src/main.rs#L46-L76 https://github.com/actix/examples/blob/master/async_db/src/m...
My suspicion is the people do this to avoid "variable does not live long enough" type errors.
- gamegoblin 8y agoI believe that is written that way because it's using futures. Once async/await lands this year, all of the futures combinator madness goes away.
- thibran 8y agoThe code could use closures to split the expression or define local functions on the bottom of the surrounding function (a.k.a Haskell style). This would increase readability a lot. Example: https://play.rust-lang.org/?gist=7ea1a39971399d0429f0369cb9ef1382&version=stable&mode=debug&edition=2015 https://play.rust-lang.org/?gist=7ea1a39971399d0429f0369cb9e...
- drudru11 8y agoThis is called the 'pyramid of doom' in the nodejs circles