Skip to content

Commit

Permalink
Add await for postShape before sending (#351)
Browse files Browse the repository at this point in the history
* Add await for postShape before sending

* Fix typo

* Resolve promises at end of loop
  • Loading branch information
gjmooney authored Apr 19, 2024
1 parent edba82a commit 89eeabc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
34 changes: 21 additions & 13 deletions packages/base/src/3dview/mainview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ import {
import { FollowIndicator } from './followindicator';
import {
BasicMesh,
buildShape,
computeExplodedState,
DEFAULT_EDGE_COLOR,
DEFAULT_EDGE_COLOR_CSS,
DEFAULT_LINEWIDTH,
DEFAULT_MESH_COLOR,
DEFAULT_MESH_COLOR_CSS,
IPickedResult,
IPointer,
projectVector,
SELECTED_LINEWIDTH,
SELECTED_MESH_COLOR,
SELECTED_MESH_COLOR_CSS
SELECTED_MESH_COLOR_CSS,
buildShape,
computeExplodedState,
projectVector
} from './helpers';
import { MainViewModel } from './mainviewmodel';
import { Spinner } from './spinner';
Expand Down Expand Up @@ -719,7 +719,7 @@ export class MainView extends React.Component<IProps, IStates> {
this._updateRefLength(true);
}

private _requestRender(
private async _requestRender(
sender: MainViewModel,
renderData: {
shapes: any;
Expand All @@ -728,6 +728,7 @@ export class MainView extends React.Component<IProps, IStates> {
}
) {
const { shapes, postShapes, postResult } = renderData;

if (shapes !== null && shapes !== undefined) {
this._shapeToMesh(renderData.shapes);
const options = {
Expand All @@ -737,6 +738,7 @@ export class MainView extends React.Component<IProps, IStates> {

if (postResult && this._meshGroup) {
const exporter = new GLTFExporter();
const promises: Promise<void>[] = [];
Object.values(postResult).forEach(pos => {
const objName = pos.jcObject.parameters?.['Object'];
if (!objName) {
Expand All @@ -748,15 +750,21 @@ export class MainView extends React.Component<IProps, IStates> {
if (!threeShape) {
return;
}
exporter.parse(
threeShape,
exported => {
pos.postShape = exported as any;
},
options
);
const promise = new Promise<void>(resolve => {
exporter.parse(
threeShape,
exported => {
pos.postShape = exported as any;
resolve();
},
options
);
});
promises.push(promise);
});
this._mainViewModel.sendRawGeomeryToWorker(postResult);

await Promise.all(promises);
this._mainViewModel.sendRawGeometryToWorker(postResult);
}
}
if (postShapes !== null && postShapes !== undefined) {
Expand Down
4 changes: 2 additions & 2 deletions packages/base/src/3dview/mainviewmodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class MainViewModel implements IDisposable {
postShapes: null,
postResult: threejsPostResult
});
this.sendRawGeomeryToWorker(rawPostResult);
this.sendRawGeometryToWorker(rawPostResult);
}

break;
Expand All @@ -138,7 +138,7 @@ export class MainViewModel implements IDisposable {
}
};

sendRawGeomeryToWorker(postResult: IDict<IPostOperatorInput>): void {
sendRawGeometryToWorker(postResult: IDict<IPostOperatorInput>): void {
Object.values(postResult).forEach(res => {
this._postWorkerId.forEach((wk, id) => {
const shape = res.jcObject.shape;
Expand Down

0 comments on commit 89eeabc

Please sign in to comment.