You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I am currently implementing a server-side specific service for my Angular application (using server-side rendering). I am experiencing an issue with calls to the database: the application do not wait for the promise with the DB result to be resolved.
I was able to track down the issue to zone.js not patching the Socket class from Node's net library. It seems that net.Socket is not patched by zone.js.
Here is a minimal example describing the issue. Both promises resolve to {foo: bar}.
The first one waits for a network packet, the second one uses a timeout.
import*asnetfrom"net";// The component does not wait for this promiseletp1=newPromise<{foo: string}>(function(resolve,reject){consts=newnet.Socket();s.connect(80,"example.com");s.write(newBuffer("GET /index.html HTTP/1.1\nHost: example.com\n\n"));s.on("data",function(data){resolve({foo: "bar"});});});// The component waits for this promiseletp2=newPromise<{foo: string}>(function(resolve,reject){setTimeout(()=>resolve({foo: "bar"}),100);});
I do not know zone.js very well, but I know that it patches most of the asynchronous functions such as setTimeout, Promises, even Node's EventEmitter and http client so I was surprised that this does not work.
I'll try to learn more about zone.js in the next days to have a better understanding of the issue. In the meantime, is there a workaround ?
Hi,
I am currently implementing a server-side specific service for my Angular application (using server-side rendering). I am experiencing an issue with calls to the database: the application do not wait for the promise with the DB result to be resolved.
I was able to track down the issue to zone.js not patching the
Socketclass from Node'snetlibrary.It seems that
net.Socketis not patched byzone.js.Here is a minimal example describing the issue. Both promises resolve to
{foo: bar}.The first one waits for a network packet, the second one uses a timeout.
I do not know
zone.jsvery well, but I know that it patches most of the asynchronous functions such as setTimeout, Promises, even Node's EventEmitter and http client so I was surprised that this does not work.I'll try to learn more about zone.js in the next days to have a better understanding of the issue. In the meantime, is there a workaround ?