Skip to content

Commit

Permalink
Support async linking in copyWorkbook (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
imsitnikov authored Aug 27, 2024
1 parent 46d6944 commit 8030af5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/services/new/workbook/copy-workbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,18 @@ export async function crossSyncCopiedJoinedEntryRevisions({
newByOldEntryIdMap.set(encodedTargetConnectionId, encodedTemplateConnectionId);
}

await Utils.waitNextMacrotask();
let strCopiedJoinedEntryRevisions = JSON.stringify(arCopiedJoinedEntryRevisions);
newByOldEntryIdMap.forEach((value, key) => {

for (const [key, value] of newByOldEntryIdMap) {
await Utils.waitNextMacrotask();
strCopiedJoinedEntryRevisions = strCopiedJoinedEntryRevisions.replace(
new RegExp(value, 'g'),
key,
);
});
}

await Utils.waitNextMacrotask();
const arCopiedJoinedEntryRevisionsWithReplacedIds = JSON.parse(
strCopiedJoinedEntryRevisions,
) as JoinedEntryRevisionColumns[];
Expand Down
6 changes: 6 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ export class Utils {
return results;
}

static waitNextMacrotask = async () => {
return new Promise((resolve) => {
setImmediate(resolve);
});
};

static encodeId(bigIntId: any) {
let encodedId = '';

Expand Down

0 comments on commit 8030af5

Please sign in to comment.