Skip to content

Commit

Permalink
Merge pull request #10347 from keymanapp/change/web/lmworker-async-co…
Browse files Browse the repository at this point in the history
…rrections

change(web): more prep for better async prediction handling 🕐
  • Loading branch information
jahorton authored Jun 14, 2024
2 parents cb8919a + 17787b9 commit fe320ea
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ export class SearchSpace {
}

// Current best guesstimate of how compositor will retrieve ideal corrections.
*getBestMatches(waitMillis?: number): Generator<SearchResult[]> {
async *getBestMatches(waitMillis?: number): AsyncGenerator<SearchResult[]> {
// might should also include a 'base cost' parameter of sorts?
let searchSpace = this;
let currentReturns: {[mapKey: string]: SearchNode} = {};
Expand Down
2 changes: 1 addition & 1 deletion common/web/lm-worker/src/main/model-compositor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export default class ModelCompositor {

let bestCorrectionCost: number;
const SEARCH_TIMEOUT = this.testMode ? 0 : correction.SearchSpace.DEFAULT_ALLOTTED_CORRECTION_TIME_INTERVAL;
for(let matches of searchSpace.getBestMatches(SEARCH_TIMEOUT)) {
for await(let matches of searchSpace.getBestMatches(SEARCH_TIMEOUT)) {
// Corrections obtained: now to predict from them!
let predictionRoots = matches.map(function(match) {
let correction = match.matchString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ describe('Correction Distance Modeler', function() {
testModel = new models.TrieModel(jsonFixture('models/tries/english-1000'));
});

let checkResults_teh = function(iter) {
let firstSet = iter.next(); // {value: <actual value>, done: <iteration complete?>}
let checkResults_teh = async function(iter) {
let firstSet = await iter.next(); // {value: <actual value>, done: <iteration complete?>}
assert.isFalse(firstSet.done);

firstSet = firstSet.value; // Retrieves <actual value>
Expand All @@ -264,7 +264,7 @@ describe('Correction Distance Modeler', function() {
'the'
];

let secondSet = iter.next(); // {value: <actual value>, done: <iteration complete?>}
let secondSet = await iter.next(); // {value: <actual value>, done: <iteration complete?>}
assert.isFalse(secondSet.done);

secondSet = secondSet.value; // Retrieves <actual value>
Expand All @@ -282,7 +282,7 @@ describe('Correction Distance Modeler', function() {
'thu', 'wen'
];

let thirdSet = iter.next(); // {value: <actual value>, done: <iteration complete?>}
let thirdSet = await iter.next(); // {value: <actual value>, done: <iteration complete?>}
assert.isFalse(thirdSet.done);

thirdSet = thirdSet.value; // Retrieves <actual value>
Expand All @@ -293,19 +293,19 @@ describe('Correction Distance Modeler', function() {
assert.deepEqual(entries, thirdBatch);
}

it('Simple search without input', function() {
it('Simple search without input', async function() {
// The combinatorial effect here is a bit much to fully test.
let rootTraversal = testModel.traverseFromRoot();
assert.isNotEmpty(rootTraversal);

let searchSpace = new correction.SearchSpace(testModel);

let iter = searchSpace.getBestMatches();
let firstSet = iter.next();
let firstSet = await iter.next();
assert.isFalse(firstSet.done);
});

it('Simple search (paralleling "Small integration test")', function() {
it('Simple search (paralleling "Small integration test")', async function() {
// The combinatorial effect here is a bit much to fully test.
let rootTraversal = testModel.traverseFromRoot();
assert.isNotEmpty(rootTraversal);
Expand All @@ -332,7 +332,7 @@ describe('Correction Distance Modeler', function() {
searchSpace.addInput(synthDistribution3);

let iter = searchSpace.getBestMatches(0); // disables the correction-search timeout.
checkResults_teh(iter);
await checkResults_teh(iter);

// // Debugging method: a simple loop for printing out the generated sets, in succession.
// //
Expand All @@ -359,7 +359,7 @@ describe('Correction Distance Modeler', function() {
// }
});

it('Allows reiteration (sequentially)', function() {
it('Allows reiteration (sequentially)', async function() {
// The combinatorial effect here is a bit much to fully test.
let rootTraversal = testModel.traverseFromRoot();
assert.isNotEmpty(rootTraversal);
Expand All @@ -386,15 +386,15 @@ describe('Correction Distance Modeler', function() {
searchSpace.addInput(synthDistribution3);

let iter = searchSpace.getBestMatches(0); // disables the correction-search timeout.
checkResults_teh(iter);
await checkResults_teh(iter);

// The key: do we get the same results the second time?
// Reset the iterator first...
let iter2 = searchSpace.getBestMatches(0); // disables the correction-search timeout.
checkResults_teh(iter2);
await checkResults_teh(iter2);
});

it('Empty search space, loaded model', function() {
it('Empty search space, loaded model', async function() {
// The combinatorial effect here is a bit much to fully test.
let rootTraversal = testModel.traverseFromRoot();
assert.isNotEmpty(rootTraversal);
Expand All @@ -403,7 +403,7 @@ describe('Correction Distance Modeler', function() {
let iter = searchSpace.getBestMatches();

// While there's no input, insertion operations can produce suggestions.
let resultState = iter.next();
let resultState = await iter.next();
let results = resultState.value;

// Just one suggestion should be returned.
Expand Down

0 comments on commit fe320ea

Please sign in to comment.