Skip to content

Commit

Permalink
remove request
Browse files Browse the repository at this point in the history
  • Loading branch information
yann300 committed Oct 7, 2024
1 parent d8dbecf commit 7c635ee
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
24 changes: 15 additions & 9 deletions apps/remix-ide/src/blockchain/providers/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,22 @@ export class VMProvider {

return new Promise((resolve, reject) => {
this.worker.addEventListener('message', (msg) => {
if (msg.data.cmd === 'sendAsyncResult' && stamps[msg.data.stamp]) {
const result = msg.data.result
// if (stamps[msg.data.stamp].request && msg.data.result) result = msg.data.result.result

console.log('message', msg)
if (msg.data.cmd === 'requestResult' && stamps[msg.data.stamp]) {
if (msg.data.error) {
stamps[msg.data.stamp].reject(msg.data.error)
} else {
stamps[msg.data.stamp].resolve(msg.data.result)
}
} else if (msg.data.cmd === 'sendAsyncResult' && stamps[msg.data.stamp]) {
if (stamps[msg.data.stamp].callback) {
stamps[msg.data.stamp].callback(msg.data.error, result)
stamps[msg.data.stamp].callback(msg.data.error, msg.data.result)
return
}
if (msg.data.error) {
stamps[msg.data.stamp].reject(msg.data.error)
} else {
stamps[msg.data.stamp].resolve(result)
stamps[msg.data.stamp].resolve(msg.data.result)
}
} else if (msg.data.cmd === 'initiateResult') {
if (!msg.data.error) {
Expand All @@ -58,16 +62,18 @@ export class VMProvider {
return new Promise((resolve, reject) => {
const stamp = Date.now() + incr
incr++
stamps[stamp] = { callback, resolve, reject, sendAsync: true }
stamps[stamp] = { callback, resolve, reject }
console.log('sendAsync', query, stamp)
this.worker.postMessage({ cmd: 'sendAsync', query, stamp })
})
},
request: (query) => {
return new Promise((resolve, reject) => {
const stamp = Date.now() + incr
incr++
stamps[stamp] = { resolve, reject, request: true }
this.worker.postMessage({ cmd: 'sendAsync', query, stamp })
stamps[stamp] = { resolve, reject }
console.log('request', query, stamp)
this.worker.postMessage({ cmd: 'request', query, stamp })
})
}
}
Expand Down
31 changes: 31 additions & 0 deletions apps/remix-ide/src/blockchain/providers/worker-vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,37 @@ self.onmessage = (e: MessageEvent) => {

break
}
case 'request':
{
(function (data) {
const stamp = data.stamp
if (provider) {
provider.request(data.query).then((result) => {
self.postMessage({
cmd: 'requestResult',
error: null,
result: result,
stamp: stamp
})
}).catch((error) => {
self.postMessage({
cmd: 'requestResult',
error: error,
result: null,
stamp: stamp
})
})
} else {
self.postMessage({
cmd: 'requestResult',
error: 'Provider not instantiated',
result: null,
stamp: stamp
})
}
})(data)
break
}
case 'addAccount':
{
if (provider) {
Expand Down

0 comments on commit 7c635ee

Please sign in to comment.