Remove double async wrapping
Summary: Our usage of requestIdleCallback (probably) causes more trouble than it solves: 1. It makes sure everything is processed asynchronously. But since everything is arriving over a network stack, that is already the case without wrapping it again to run on a separate event loop tick 2. The timeout we set before `500` forces the app to give _more_ priority to message processing instead of less 3. In a next diff (D20151700) in this stack we will make sure that messages are not processed immediately, but simple stored, which should not be significantly more expensive (probably even cheaper) than scheduling another tick on the event loop Reviewed By: jknoxville Differential Revision: D20557104 fbshipit-source-id: 6cc10ba537e3cb5f31e6c32e1fdeb57c20f06f17
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d103692883
commit
aa2879d6e8
@@ -121,7 +121,6 @@ export default class Client extends EventEmitter {
|
||||
logger: Logger;
|
||||
lastSeenDeviceList: Array<BaseDevice>;
|
||||
broadcastCallbacks: Map<string, Map<string, Set<Function>>>;
|
||||
rIC: any;
|
||||
|
||||
requestCallbacks: Map<
|
||||
number,
|
||||
@@ -167,14 +166,6 @@ export default class Client extends EventEmitter {
|
||||
}
|
||||
|
||||
const client = this;
|
||||
// node.js doesn't support requestIdleCallback
|
||||
this.rIC =
|
||||
typeof window === 'undefined' || !window.requestIdleCallback
|
||||
? (cb: Function, _: any) => {
|
||||
cb();
|
||||
}
|
||||
: window.requestIdleCallback.bind(window);
|
||||
|
||||
if (conn) {
|
||||
conn.connectionStatus().subscribe({
|
||||
onNext(payload) {
|
||||
|
||||
@@ -252,7 +252,10 @@ class Server extends EventEmitter {
|
||||
socket,
|
||||
{app, os, device, device_id, sdk_version},
|
||||
{csr, csr_path},
|
||||
);
|
||||
).then(client => {
|
||||
return (resolvedClient = client);
|
||||
});
|
||||
let resolvedClient: Client | undefined;
|
||||
|
||||
socket.connectionStatus().subscribe({
|
||||
onNext(payload) {
|
||||
@@ -269,12 +272,15 @@ class Server extends EventEmitter {
|
||||
});
|
||||
|
||||
return {
|
||||
fireAndForget: (payload: {data: string}) =>
|
||||
client.then(client => {
|
||||
client.rIC(() => client.onMessage(payload.data), {
|
||||
timeout: 500,
|
||||
fireAndForget: (payload: {data: string}) => {
|
||||
if (resolvedClient) {
|
||||
resolvedClient.onMessage(payload.data);
|
||||
} else {
|
||||
client.then(client => {
|
||||
client.onMessage(payload.data);
|
||||
});
|
||||
}),
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user