diff options
author | Sam Wilkins <samwilkins333@gmail.com> | 2019-08-01 02:31:07 -0400 |
---|---|---|
committer | Sam Wilkins <samwilkins333@gmail.com> | 2019-08-01 02:31:07 -0400 |
commit | cd02f494975ad44b85c08d3108f185edbea43258 (patch) | |
tree | 1c4f30004385d5ffc711032f51cb8cfc5be00898 /src/client/DocServer.ts | |
parent | ec224416fc454c7fdbb62943408226c973d8c751 (diff) | |
parent | d4accdd22cabdd78fc7bd76dd7ce3cb59e4b102f (diff) |
Merge branch 'master' into speech-to-text
Diffstat (limited to 'src/client/DocServer.ts')
-rw-r--r-- | src/client/DocServer.ts | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/client/DocServer.ts b/src/client/DocServer.ts index 258acd9cd..fc39fa364 100644 --- a/src/client/DocServer.ts +++ b/src/client/DocServer.ts @@ -124,16 +124,17 @@ export namespace DocServer { // future .proto calls on the Doc won't have to go farther than the cache to get their actual value. const deserializeField = getSerializedField.then(async fieldJson => { // deserialize - const field = await SerializationHelper.Deserialize(fieldJson); + const field = await SerializationHelper.Deserialize(fieldJson, val => { + if (val !== undefined) { + _cache[id] = val; + } else { + delete _cache[id]; + } + }); + return field; // either way, overwrite or delete any promises cached at this id (that we inserted as flags // to indicate that the field was in the process of being fetched). Now everything // should be an actual value within or entirely absent from the cache. - if (field !== undefined) { - _cache[id] = field; - } else { - delete _cache[id]; - } - return field; }); // here, indicate that the document associated with this id is currently // being retrieved and cached @@ -214,15 +215,23 @@ export namespace DocServer { const deserializeFields = getSerializedFields.then(async fields => { const fieldMap: { [id: string]: RefField } = {}; // const protosToLoad: any = []; + const proms: Promise<RefField>[] = []; for (const field of fields) { if (field !== undefined) { // deserialize - let deserialized = await SerializationHelper.Deserialize(field); - fieldMap[field.id] = deserialized; + let prom = SerializationHelper.Deserialize(field, val => { + if (val !== undefined) { + _cache[field.id] = field; + } else { + delete _cache[field.id]; + } + }).then(deserialized => fieldMap[field.id] = deserialized); + proms.push(prom); // adds to a list of promises that will be awaited asynchronously // protosToLoad.push(deserialized.proto); } } + await Promise.all(proms); // this actually handles the loading of prototypes // await Promise.all(protosToLoad); return fieldMap; |