Skip to content

Commit 89eeabc

Browse files
authored
Add await for postShape before sending (#351)
* Add await for postShape before sending * Fix typo * Resolve promises at end of loop
1 parent edba82a commit 89eeabc

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

packages/base/src/3dview/mainview.tsx

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ import {
3434
import { FollowIndicator } from './followindicator';
3535
import {
3636
BasicMesh,
37-
buildShape,
38-
computeExplodedState,
3937
DEFAULT_EDGE_COLOR,
4038
DEFAULT_EDGE_COLOR_CSS,
4139
DEFAULT_LINEWIDTH,
4240
DEFAULT_MESH_COLOR,
4341
DEFAULT_MESH_COLOR_CSS,
4442
IPickedResult,
4543
IPointer,
46-
projectVector,
4744
SELECTED_LINEWIDTH,
4845
SELECTED_MESH_COLOR,
49-
SELECTED_MESH_COLOR_CSS
46+
SELECTED_MESH_COLOR_CSS,
47+
buildShape,
48+
computeExplodedState,
49+
projectVector
5050
} from './helpers';
5151
import { MainViewModel } from './mainviewmodel';
5252
import { Spinner } from './spinner';
@@ -719,7 +719,7 @@ export class MainView extends React.Component<IProps, IStates> {
719719
this._updateRefLength(true);
720720
}
721721

722-
private _requestRender(
722+
private async _requestRender(
723723
sender: MainViewModel,
724724
renderData: {
725725
shapes: any;
@@ -728,6 +728,7 @@ export class MainView extends React.Component<IProps, IStates> {
728728
}
729729
) {
730730
const { shapes, postShapes, postResult } = renderData;
731+
731732
if (shapes !== null && shapes !== undefined) {
732733
this._shapeToMesh(renderData.shapes);
733734
const options = {
@@ -737,6 +738,7 @@ export class MainView extends React.Component<IProps, IStates> {
737738

738739
if (postResult && this._meshGroup) {
739740
const exporter = new GLTFExporter();
741+
const promises: Promise<void>[] = [];
740742
Object.values(postResult).forEach(pos => {
741743
const objName = pos.jcObject.parameters?.['Object'];
742744
if (!objName) {
@@ -748,15 +750,21 @@ export class MainView extends React.Component<IProps, IStates> {
748750
if (!threeShape) {
749751
return;
750752
}
751-
exporter.parse(
752-
threeShape,
753-
exported => {
754-
pos.postShape = exported as any;
755-
},
756-
options
757-
);
753+
const promise = new Promise<void>(resolve => {
754+
exporter.parse(
755+
threeShape,
756+
exported => {
757+
pos.postShape = exported as any;
758+
resolve();
759+
},
760+
options
761+
);
762+
});
763+
promises.push(promise);
758764
});
759-
this._mainViewModel.sendRawGeomeryToWorker(postResult);
765+
766+
await Promise.all(promises);
767+
this._mainViewModel.sendRawGeometryToWorker(postResult);
760768
}
761769
}
762770
if (postShapes !== null && postShapes !== undefined) {

packages/base/src/3dview/mainviewmodel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class MainViewModel implements IDisposable {
117117
postShapes: null,
118118
postResult: threejsPostResult
119119
});
120-
this.sendRawGeomeryToWorker(rawPostResult);
120+
this.sendRawGeometryToWorker(rawPostResult);
121121
}
122122

123123
break;
@@ -138,7 +138,7 @@ export class MainViewModel implements IDisposable {
138138
}
139139
};
140140

141-
sendRawGeomeryToWorker(postResult: IDict<IPostOperatorInput>): void {
141+
sendRawGeometryToWorker(postResult: IDict<IPostOperatorInput>): void {
142142
Object.values(postResult).forEach(res => {
143143
this._postWorkerId.forEach((wk, id) => {
144144
const shape = res.jcObject.shape;

0 commit comments

Comments
 (0)