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 appScanWorker = new AppScanWorker()
|
||||||
|
|
||||||
|
const fileArrayBuffer = ( typeof file.arrayBuffer === 'function' ) ? (await file.arrayBuffer()) : file.arrayBuffer
|
||||||
|
|
||||||
const scan = await new Promise( ( resolve, reject ) => {
|
const scan = await new Promise( ( resolve, reject ) => {
|
||||||
// Set up the worker message handler
|
// Set up the worker message handler
|
||||||
appScanWorker.onmessage = async (event) => {
|
appScanWorker.onmessage = async (event) => {
|
||||||
|
|
@ -30,15 +32,20 @@ export async function runScanWorker ( file ) {
|
||||||
appScanWorker.postMessage( {
|
appScanWorker.postMessage( {
|
||||||
status: 'start',
|
status: 'start',
|
||||||
options: {
|
options: {
|
||||||
fileLoader: () => ({
|
file: {
|
||||||
...file,
|
...file,
|
||||||
arrayBuffer: file.arrayBuffer
|
// We put it into an array
|
||||||
}),
|
// so that it's iterable for Blob
|
||||||
messageReceiver: ( details ) => {
|
arrayBuffer: [ fileArrayBuffer ]
|
||||||
console.log( 'Scan message:', details )
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [ 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 {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,11 @@ self.onmessage = async ( event ) => {
|
||||||
if ( status === 'start' ) {
|
if ( status === 'start' ) {
|
||||||
// Get Scan Options
|
// Get Scan Options
|
||||||
const { options } = event.data
|
const { options } = event.data
|
||||||
|
|
||||||
// console.log( 'options', options )
|
// console.log( 'options', options )
|
||||||
|
|
||||||
const scan = new AppScan({
|
const scan = new AppScan({
|
||||||
...options,
|
fileLoader: () => options.file,
|
||||||
// Use self.postMessage as the message callback
|
// Use self.postMessage as the message callback
|
||||||
messageReceiver: ( message ) => {
|
messageReceiver: ( message ) => {
|
||||||
self.postMessage( message )
|
self.postMessage( message )
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue