Ваш patientService
возвращает Observable, поэтому functionCall searchPatientById()
является асинхронным. Это означает, что после вызова функции последующие строки будут выполнены, и часть в subscribe
будет выполнена, когда вы получите результат.
Чтобы избежать этого, у вас есть больше опций, например, вы можете создать другой метод, который должен быть выполнен ПОСЛЕ асинхронного вызова и чем вызывать этот метод в конце в subscribe
. Или вы можете использовать async/await
так:
constructor(public navCtrl: NavController, public navParams: NavParams, public
patientService: PatientServiceProvider, public scanner: BarcodeScanner) {
this.init();
}
async init() {
this.id = this.navParams.get('id');
let res = await this.patientService.searchPatientById(this.id);
this.id = res.id;
this.mobile = res.mobile;
this.fname = res.firstname;
this.lname = res.lastName;
console.log("print this:"+this.mobile);
this.mobile = this.navParams.get('mobile');
console.log(this.id);
console.log("****"+this.mobile);
}
Since your code is equivalent to
consume store (x:xs) = putMVar store >> consume store xs
the call does not actually occur in tail position. But if you run ghc -O
and turn on the optimizer, the -ddump-simpl
option will show you the output of GHC's intermediate code, and it does indeed optimize into a tail-recursive function, which will compile into a loop.
So the answer is GHC won't optimize this by default; you need the -O
option.
(Experiments done with GHC version 6.10.1.)