Skip to content

Unable to rebind ECMAScript instance from godot object in threaded worker.js #108

Open
@dangerousbeans

Description

@dangerousbeans

My main thread is sending out a ECMAscript class as a message to a worker thread using godot.abandon_value & godot.adopt_value, but I only get the godot object and cannot call any of the js methods on the class:

// parcel.tsx
export default class Parcel extends godot.Spatial {
  test_function(){
    console.log("stuff I wana run here"))
  }
}

// worker.js
onmessage = function(e) {
  let parcel = godot.adopt_value(e.parcel)
  console.log(parcel)                                 // [Spatial:2362]
  console.log(parcel.test_function())         // undefined
  console.log(parcel.call("test_function")) // error
}

// grid.tsx
export default class Grid  extends godot.Spatial {
  featureLoadThread

  _ready(){
    let p = new Parcel()

    this.featureLoadThread = new Worker('res://src/worker.js')
    this.featureLoadThread.onmessage = this._onmessage.bind(this);
    this.featureLoadThread.postMessage({ type:"featureLoad", parcel: godot.abandon_value(p) })
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions