deepstreamIO / deepstream.io

deepstream.io server
https://deepstreamio.github.io
MIT License
7.14k stars 381 forks source link

Misleading record.whenReady and record.isReady #995

Closed alanhoff closed 5 years ago

alanhoff commented 5 years ago

Versions:

In this test the hello-world record contains a simple object: {hello: 'world'}. The test file:

const deepstream = require('@deepstream/client');
const client = deepstream('ws://localhost:6020');

client.login();

const record = client.record.getRecord('hello-world');

record.whenReady(() => {
  console.log('event: whenReady', `ready: ${record.isReady}`, JSON.stringify(record.get()));
});

record.subscribe(() => {
  console.log('event: subscribe', `ready: ${record.isReady}`, JSON.stringify(record.get()));
});

What I expected to see in my console is the following:

event: subscribe ready: false {}
event: whenReady ready: true {"hello": "world"}
event: subscribe ready: true {"hello": "world"}

But what I get is this:

Screen Shot 2019-09-11 at 11 36 52

The first log shows that record.isReady is true when it's clearly not. The second log is triggered by whenReady but as you can see the document is still empty so it's not actually ready. The third log is a total mystery why it happens because nothing has changed since the first subscribe event. Only in the fourth log the record contains all the data from the server.

Question: How do I know when the record is truly ready?

alanhoff commented 5 years ago

Wrong repository...