Thanks to visit codestin.com
Credit goes to github.com

Skip to content

How could nativescript yield the execution to let UI redraw.  #2382

Closed
@ryc16

Description

@ryc16

I read some discussion where Nativescript not yet have background worker and everything is running UI thread. Is there any way to yield the execution to let UI redraw.

Bolow is a good example from one of plugins people implemented to read the phone contacts. If there is 1000 contacts, the UI is totally blocked for few mins. Any idea to yield the execution.

exports.getAllContacts = function(){
    return new Promise(function (resolve, reject){
        var c = appModule.android.context.getContentResolver().query(android.provider.ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

        if(c.getCount() > 0){
            var cts = [];
            while(c.moveToNext()){
                var contactModel = new Contact();
                contactModel.initializeFromNative(c);
                cts.push(contactModel);
            }
            c.close();
            resolve({
                data: cts,
                response: "fetch"
            });
        }
        else{
            c.close();
            resolve({
                data: null,
                response: "fetch"
            });
        }
    });
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions