SyncMessenger.d.ts 1.0 KB

123456789101112131415161718192021222324
  1. export type AsyncCallback = (request: Uint8Array) => Promise<Uint8Array>;
  2. /**
  3. * `SyncMessenger` allows to execute asynchronous code synchronously. The
  4. * asynchronous code is executed in a Worker thread, while the main thread is
  5. * blocked until the asynchronous code is finished.
  6. *
  7. * First four 4-byte words is the header, where the first word is used for Atomics
  8. * notifications. The second word is used for spin-locking the main thread until
  9. * the asynchronous code is finished. The third word is used to specify payload
  10. * length. The fourth word is currently unused.
  11. *
  12. * The maximum payload size is the size of the SharedArrayBuffer minus the
  13. * header size.
  14. */
  15. export declare class SyncMessenger {
  16. protected readonly sab: SharedArrayBuffer;
  17. protected readonly int32: Int32Array;
  18. protected readonly uint8: Uint8Array;
  19. protected readonly headerSize: any;
  20. protected readonly dataSize: any;
  21. constructor(sab: SharedArrayBuffer);
  22. callSync(data: Uint8Array): Uint8Array;
  23. serveAsync(callback: AsyncCallback): void;
  24. }