Skip to content

Commit

Permalink
fixed incorrect typing
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Jun 18, 2020
1 parent 5655085 commit bda02bd
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/core/server/saved_objects/migrations/core/migrate_raw_docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
* This file provides logic for migrating raw documents.
*/

import { SavedObjectsRawDoc, SavedObjectsSerializer } from '../../serialization';
import {
SavedObjectsRawDoc,
SavedObjectsSerializer,
SavedObjectUnsanitizedDoc,
} from '../../serialization';
import { TransformFn } from './document_migrator';
import { SavedObjectsMigrationLogger } from '.';

Expand All @@ -38,7 +42,7 @@ export async function migrateRawDocs(
migrateDoc: TransformFn,
rawDocs: SavedObjectsRawDoc[],
log: SavedObjectsMigrationLogger
): SavedObjectsRawDoc[] {
): Promise<SavedObjectsRawDoc[]> {
const migrateDocWithoutBlocking = transformNonBlocking(migrateDoc);
const processesDocs = [];
for (const raw of rawDocs) {
Expand All @@ -62,13 +66,15 @@ export async function migrateRawDocs(
return processesDocs;
}

function transformNonBlocking(transform: TransformFn): Promise<ReturnType<TransformFn>> {
function transformNonBlocking(
transform: TransformFn
): (doc: SavedObjectUnsanitizedDoc) => Promise<SavedObjectUnsanitizedDoc> {
// promises aren't enough to unblock the event loop
return (...args) =>
return (doc: SavedObjectUnsanitizedDoc) =>
new Promise((resolve) => {
// set immediate is though
setImmediate(() => {
resolve(transform(...args));
resolve(transform(doc));
});
});
}

0 comments on commit bda02bd

Please sign in to comment.