diff --git a/src/util/actor.js b/src/util/actor.js index 0724954540c..4347918ef06 100644 --- a/src/util/actor.js +++ b/src/util/actor.js @@ -29,8 +29,6 @@ class Actor { cancelCallbacks: { number: Cancelable }; invoker: ThrottledInvoker; - static taskId: number; - constructor(target: any, parent: any, mapId: ?number) { this.target = target; this.parent = parent; @@ -53,7 +51,11 @@ class Actor { * @private */ send(type: string, data: mixed, callback: ?Function, targetMapId: ?string): ?Cancelable { - const id = ++Actor.taskId; + // We're using a string ID instead of numbers because they are being used as object keys + // anyway, and thus stringified implicitly. We use random IDs because an actor may receive + // message from multiple other actors which could run in different execution context. A + // linearly increasing ID could produce collisions. + const id = Math.round((Math.random() * 1e18)).toString(36).substring(0, 10); if (callback) { this.callbacks[id] = callback; } @@ -192,6 +194,4 @@ class Actor { } } -Actor.taskId = 0; - export default Actor;