question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not working with async results

See original GitHub issue

Hi there,

I’m using Ionic 3.4.2, and with async results, it doesn’t seems to work:

Here’s my service:

import { CompanyService } from './company.service';
import { AutoCompleteService } from 'ionic2-auto-complete';
import { Injectable } from "@angular/core";

import * as _ from 'lodash';


@Injectable()
export class CompanyCompleteService implements AutoCompleteService {
    labelAttribute = "name";

    constructor(
        private companyService: CompanyService
    ) {

    }
    public async getResults(keyword: string) {
        let jobs = await this.companyService.listJobs();

        let results =  _.filter(jobs, j => {
            return j.name.toLowerCase().startsWith(keyword.toLowerCase())
        });

        console.log('results', results);

        return results;
    }
}

I have results logged in results : image

Any ideas?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
HugoHeneaultcommented, Aug 8, 2017

I found a way to let it work with async function 😃

public getResults(keyword: string) {
        let results = new BehaviorSubject([]);

        // use a timeout to allow async function use
        setTimeout(async () => {
            let jobs = await this.companyService.listJobs();
            results.next(_.filter(jobs, j => {
                return j.name.toLowerCase().startsWith(keyword.toLowerCase())
            }));
        });

        return results;
    }

But async function should be handled by default! 👍

0reactions
HugoHeneaultcommented, Aug 9, 2017

No problem! If I have some time I can try to fix this. Shouldn’t be that hard.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why doesn't my async function return any result?
If async-await does not work for some reason, use then clause: warte(aufgabe).then(value => { var ergebnis = value; });.
Read more >
Asynchronous programming: futures, async, await | Dart
To interact with these asynchronous results, you can use the async and await keywords. ... This example shows how *not* to write asynchronous...
Read more >
Use Promise.all to Stop Async/Await from Blocking Execution ...
In async functions, await blocks any code that follows from executing until the Promise has resolves, which means that our refactored code doesn't...
Read more >
Asynchronous programming in C# | Microsoft Learn
Cooking breakfast is a good example of asynchronous work that isn't parallel. One person (or thread) can handle all these tasks.
Read more >
await - JavaScript - MDN Web Docs
It can only be used inside an async function or at the top level of a module. ... all while not blocking other...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found