refactor(struct): replace bluebird with native Promise

This commit is contained in:
Simon Chan 2022-05-14 18:10:47 +08:00
parent 1ee03486a6
commit 7d5445aeae
No known key found for this signature in database
GPG key ID: A8B69F750B9BCEDD
8 changed files with 1357 additions and 1336 deletions

View file

@ -2,7 +2,7 @@
import type { StructAsyncDeserializeStream, StructDeserializeStream, StructFieldDefinition, StructFieldValue, StructOptions } from './basic/index.js';
import { StructDefaultOptions, StructValue } from './basic/index.js';
import { Syncbird } from "./syncbird.js";
import { SyncPromise } from "./sync-promise.js";
import { BigIntFieldDefinition, BigIntFieldType, BufferFieldSubType, FixedLengthBufferLikeFieldDefinition, NumberFieldDefinition, NumberFieldType, StringBufferFieldSubType, Uint8ArrayBufferFieldSubType, VariableLengthBufferLikeFieldDefinition, type FixedLengthBufferLikeFieldOptions, type LengthField, type VariableLengthBufferLikeFieldOptions } from './types/index.js';
import type { Evaluate, Identity, Overwrite, ValueOrPromise } from "./utils.js";
@ -545,13 +545,15 @@ export class Struct<
const value = new StructValue();
Object.defineProperties(value.value, this._extra);
return Syncbird
return SyncPromise
.each(this._fields, ([name, definition]) => {
return Syncbird.resolve(
definition.deserialize(this.options, stream as any, value)
).then(fieldValue => {
value.set(name, fieldValue);
});
return SyncPromise
.try(() => {
return definition.deserialize(this.options, stream as any, value);
})
.then(fieldValue => {
value.set(name, fieldValue);
});
})
.then(() => {
const object = value.value;