mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-15 06:35:20 -07:00
Fix data not transferring into Worker
This commit is contained in:
parent
f73635de08
commit
6b08545081
2 changed files with 16 additions and 7 deletions
|
|
@ -5,6 +5,8 @@ export async function runScanWorker ( file ) {
|
|||
|
||||
const appScanWorker = new AppScanWorker()
|
||||
|
||||
const fileArrayBuffer = ( typeof file.arrayBuffer === 'function' ) ? (await file.arrayBuffer()) : file.arrayBuffer
|
||||
|
||||
const scan = await new Promise( ( resolve, reject ) => {
|
||||
// Set up the worker message handler
|
||||
appScanWorker.onmessage = async (event) => {
|
||||
|
|
@ -30,15 +32,20 @@ export async function runScanWorker ( file ) {
|
|||
appScanWorker.postMessage( {
|
||||
status: 'start',
|
||||
options: {
|
||||
fileLoader: () => ({
|
||||
file: {
|
||||
...file,
|
||||
arrayBuffer: file.arrayBuffer
|
||||
}),
|
||||
messageReceiver: ( details ) => {
|
||||
console.log( 'Scan message:', details )
|
||||
// We put it into an array
|
||||
// so that it's iterable for Blob
|
||||
arrayBuffer: [ fileArrayBuffer ]
|
||||
}
|
||||
}
|
||||
}, [ file.arrayBuffer ] )
|
||||
}, [
|
||||
// This array is our transferrable objects
|
||||
// so that the App Scan Worker is allowed
|
||||
// to use existing data from the main thread
|
||||
// and we don't have to clone the data from scratch
|
||||
fileArrayBuffer
|
||||
] )
|
||||
})
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -13,9 +13,11 @@ self.onmessage = async ( event ) => {
|
|||
if ( status === 'start' ) {
|
||||
// Get Scan Options
|
||||
const { options } = event.data
|
||||
|
||||
// console.log( 'options', options )
|
||||
|
||||
const scan = new AppScan({
|
||||
...options,
|
||||
fileLoader: () => options.file,
|
||||
// Use self.postMessage as the message callback
|
||||
messageReceiver: ( message ) => {
|
||||
self.postMessage( message )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue