How to dismiss LoadingController through code in Ionic 5 app?

In my Ionic 5 app, I am displaying a LoadingController like so:

async presentLoading() {
    const loading = await this.loadingCtrl.create({
      message: 'Please wait...',
    await loading.present();

getPosts() {

      .then((docs) => {
        docs.forEach((doc) => {
        this.cursor = this.posts[this.posts.length - 1];
      }).catch((err) => {

Once this.posts is populated, I want the LoadingController to be dismissed.

Can someone please tell me how to do this? Thanks a lot in advance!

I would return the loading indicator out of presentLoading and call dismiss on it.