Skip to content

Commit

Permalink
fix: response when calling extension host command
Browse files Browse the repository at this point in the history
  • Loading branch information
levivilet committed Sep 1, 2024
1 parent c5b8877 commit 3d9bd75
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/parts/PreviewInjectedCode/PreviewInjectedCode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
export const injectedCode = `
let commandMap = {}
let port
let id = 0
const createId = () => {
return ++id
}
const callbacks = Object.create(null)
Expand All @@ -12,6 +17,7 @@ const handleMessage = async (event) => {
const message = event.data
if(isJsonRpcResponse(message)){
const fn = callbacks[message.id]
delete callbacks[message.id]
fn(message.result)
return
}
Expand Down Expand Up @@ -46,9 +52,9 @@ const withResolvers = () => {
}
const registerPromise = () => {
const id = 1
const id = createId()
const {resolve, promise} = withResolvers()
callbacks[id] = { resolve }
callbacks[id] = resolve
return {
id, promise
}
Expand Down

0 comments on commit 3d9bd75

Please sign in to comment.