worker-postable automatically clone Main thread data to WebWorker thread.
It depends on mobx.
Main thread code
// Register |sendMessage|PostableContext.onMessage = worker.postMessage;;vec.arr.pushnew Vector23, 5;vec.arr.pushnew Vector210, 2;// Reference object by worker-postable so it can be posted to worker thread// |Vector2| data in |vec.arr| is also posted because |vec.arr| is also @postable and its ref count is 1. (eg: ref count of |data| is 1)refdata;// Post more datavec.arr.pushnew Vector210, 2;// Old |vec.arr| will be unreferenced and will be deleted from worker thread.// Also new |vec.arr| is referenced and will be created from worker thread.vec.arr = ;// Get Postable id of the object;worker.postMessage// Unref data. data on worker thread side will be cleaned up since ref count of |data| is now 0.unrefdata;
Worker thread code
worker-postable post and update object if the object is referenced by worker-postable at least once.
When ref count of object becomes 0, worker thread will remove its posted object from ObjectStore and will be garbage collected.