Skip to content

Commit

Permalink
Make sure that we await setup functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carifio24 committed Dec 4, 2024
1 parent 8bb534c commit bbd95f0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 29 deletions.
34 changes: 6 additions & 28 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,23 +348,17 @@ export async function createClass(options: CreateClassOptions): Promise<CreateCl
class_id: cls.id,
});

classSetupRegistry.setupFunctions(storyName)?.forEach(setup => {
console.log(setup);
setup(cls, storyName);
});
const setupFunctions = classSetupRegistry.setupFunctions(storyName);
if (setupFunctions) {
for (const setupFunc of setupFunctions) {
await setupFunc(cls, storyName);
}
}
}

return cls;
});

// Another piece of Hubble-specific functionality
// Note that we need to reload the class so that the virtual `small_class`
// column has its value populated
await cls.reload();
if (cls.asynchronous || cls.small_class) {
await addClassToMergeGroup(cls.id);
}

return { result: result, class: creationInfo };
} catch (error) {
result = (error instanceof BaseError) ? createClassResultFromError(error) : CreateClassResult.Error;
Expand Down Expand Up @@ -941,19 +935,3 @@ export async function getDashboardGroupClasses(code: string): Promise<Class[] |
});

}

export async function hubbleClassSetup(
cls: Class,
storyName: string,
) {
if (cls) {
await ClassStories.create({
story_name: storyName,
class_id: cls.id
});

if (cls.asynchronous || cls.small_class) {
await addClassToMergeGroup(cls.id);
}
}
}
2 changes: 1 addition & 1 deletion src/registries.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Class } from "./models";

type ClassSetupFunction = (cls: Class, storyName: string) => void;
type ClassSetupFunction = (cls: Class, storyName: string) => Promise<void>;

class ClassSetupRegistry {

Expand Down

0 comments on commit bbd95f0

Please sign in to comment.