Skip to content

Commit

Permalink
terminate worker after 5 seconds of inactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
chidozieononiwu committed May 6, 2024
1 parent 57c0a31 commit d9a6efe
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class ReviewContentModel
public Dictionary<string, ReviewContentModel> CrossLanguageViewContent { get; set; } = new Dictionary<string, ReviewContentModel>();
}

<<<<<<< HEAD
public class ReviewBadgeModel
{
public ReviewListItemModel Review { get; set; }
Expand All @@ -43,12 +42,12 @@ public class ReviewBadgeModel
public UserPreferenceModel UserPreference { get; set; }
public bool? ShowDocumentation { get; set; }
public bool? ShowDiffOnly { get; set; }
=======
}

public class ReviewCodePanelData
{
public IEnumerable<CommentItemModel> Comments { get; set; }
public List<APITreeNodeForAPI> APIForest { get; set; } = new List<APITreeNodeForAPI>();
public CodeDiagnostic[] Diagnostics { get; set; }
>>>>>>> 5c591dacb (Show / Hide Documentation)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
:host ::ng-deep {
.selected-item-content{
max-width: 12dvw;
max-width: 10dvw;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</div>
<div style="flex-grow: 1; min-width: 0; margin-left: 7px;">
<p-splitter
[panelSizes]="[10, 70, 20]"
[panelSizes]="[15, 65, 20]"
[minSizes]="[1, 1, 1]"
[gutterSize]="6">
<ng-template pTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,41 @@ import { Observable, Subject } from 'rxjs';
providedIn: 'root'
})
export class WorkerService {
private apiTreeBuilder : Worker;
private apiTreeBuilder : Worker | null = null;
private apiTreeMessages = new Subject<any>();
private workerTimeout : any;

constructor() {
this.startWorker();
}

startWorker() {
this.apiTreeBuilder = new Worker(new URL('../../_workers/apitree-builder.worker', import.meta.url));

this.apiTreeBuilder.onmessage = ({ data }) => {
this.apiTreeMessages.next(data);
this.resetWorkerTimeout();
};
}

postToApiTreeBuilder(message: any) {
this.apiTreeBuilder.postMessage(message);
if (!this.apiTreeBuilder) {
this.startWorker();
}

this.apiTreeBuilder!.postMessage(message);
this.resetWorkerTimeout();
}

onMessageFromApiTreeBuilder(): Observable<any> {
return this.apiTreeMessages.asObservable();
}

private resetWorkerTimeout() {
clearTimeout(this.workerTimeout);
this.workerTimeout = setTimeout(() => {
this.apiTreeBuilder!.terminate();
this.apiTreeBuilder = null;
}, 5000); // Terminate worker after 5 seconds of inactivity
}
}

0 comments on commit d9a6efe

Please sign in to comment.