How to wait for PouchDB to connect successfully

I use pouchdb on the client side (ion mobile app) couchdb on the server side.

I need to perform an operation after successfully creating pouchdb and syncing with couchdb.

since I can wait for pouchdb to complete the initial activity. Then, after only the execution of my client side begins.

Currently, the bag is running in asynchronous mode, so sometime before initializing the package, my application initializes and I get an error message for pouchdb.

+6
source share
1 answer

When working with asynchronous functions, such as waiting for a response from the server in JavaScript, you use promises or callbacks to wait for a response.

from the pouchdb docs , we can read that they provide a completely asynchronous API.

Callback :

db.get('mittens', function (error, doc) { if (error) { // oh noes! we got an error } else { // okay, doc contains our document } }); 

Promise Version :

 db.get('mittens').then(function (doc) { // okay, doc contains our document }).catch(function (err) { // oh noes! we got an error }); 
+1
source

Source: https://habr.com/ru/post/986940/


All Articles