Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc.fetch did not execute callback #461

Closed
monsterooo opened this issue Apr 11, 2021 · 1 comment
Closed

doc.fetch did not execute callback #461

monsterooo opened this issue Apr 11, 2021 · 1 comment

Comments

@monsterooo
Copy link

sharedb is a very great library, but I encountered some problems in using it. The code is in the ubuntu system

When using docIns.fetch, the callback is not executed.

My test code is as follows

import ShareDB from "sharedb";
import ShareDBPostgresql from "sharedb-postgres";
import otText from "ot-text";

const connectURL =
  "postgresql://johndoe:randompassword@localhost:5432/test-dev?schema=public";
ShareDB.types.map["json0"].registerSubtype(otText.type);
const shareDBPostgresql = ShareDBPostgresql({
  connectionString: connectURL,
});
const backend = new ShareDB({ db: shareDBPostgresql });
const connection = backend.connect();
const docIns = connection.get("sandbox", "test-doc");
console.log("started:");

async function run() {
  return new Promise((resolve, reject) => {
    try {
      docIns.fetch(function (err) {
        console.log("callback executed:", err);
        if (err) throw reject(err);
        if (docIns.type === null) {
          docIns.create({ content: { a: "abc" } });
          resolve(undefined);
        }
      });
    } catch (error) {
      console.log('error:',error)
    }
  });
}

run();

process.stdin.resume();

Executing the code, the output I get in the console is:

root@createthink:~# npx ts-node test.js
started:

The strangest thing is that this code is executed on the local mac computer and everything is normal
Mac execution output is as follows:

started:
callback execute: undefined

In addition, I just tested the windows system, it is the same problem

Excuse me, am I missing something? Thanks

@monsterooo
Copy link
Author

After several hours of debugging, I finally found the problem
The reason is:sharedb-postgres Depends on the 7.x version of the pg library. But the 7.x pg library does not support Node.js 14 version.

So I cloned sharedb-postgres and re-modified the pg dependency to 8.x

problem solved

Hope it will be helpful to those who follow :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant