Uyini umehluko phakathi Scala Future onComplete futhi andThen imisebenzi?
Kokubili `andThen` kanye `onComplete` kukuvumela ukuba ubheke umphumela wesikhathi esizayo ngokusebenzisa umsebenzi wokubuyisa. Kodwa-ke, `andThen` ingaxhunyaniswa, futhi ngokungafani ne-`onComplete`, iqinisekisa ukuthi imisebenzi yokubiza emuva izosetshenziswa kanjani. Ngaphezu kwalokho, i-callback enikezwe ku- `andThen` ingaba umsebenzi ongatheni, ophatha kuphela isethi encane yemiphumela (isibonelo, kuphela i- `Success` noma kuphela i- `Failure`).  Cabanga ngalesi sibonelo esilandelayo usebenzisa i- `andThen` ne- `map`:  ` ` ` ` I-def demoAndThen(fut: Isikhathi esizayo[Int]): Isikhathi esizayo[Int] = { fut.andThen { case Success ((value) => println ((s"andThen1: $value") } .andThen { case Success ((value) => println ((s"andThen2: $value") } . { map i => println{"ibalazwe: $i") i i } U } U ` ` ` `  Lapho `fut` igcwaliswe ngempumelelo, "andthen1:...", "andThen2:..." kanye "map:..." kuzophrintwa ngokulandelana.  Cabanga ngesibonelo esifanayo usebenzisa `onComplete` kanye `map`:  ` ` ` ` def demoOnComplete(fut: Future[Int]): Future[Int] = { futon.Complete { t: Zama[Int] => println ((s"onComplete1: $t") } futonComplete { t: Zama[Int] => println{s"onComplete2: $t") } fut.map { i => println{"ibalazwe: $i") i i } U } U ` ` ` `  Kulokhu, lapho `fut` igcwalisa ngempumelelo, "onComplete1:...", "onComplete2:..." kanye "map:..." kuzophrintwa ngokulandelana okuthile okungacacisiwe.  Nakuba i- `andThen` ixhunywe, umsebenzi wokubuyisa ucingo ngokuvamile awuthinti umphumela we- `Future`. Kodwa qaphela: uma ukubuyisa ucingo kuphonsa amaphutha athile abulalayo, ikusasa eliwumphumela ngeke liphelele.