How to use the comlink.proxy function in comlink

To help you get started, we’ve selected a few comlink examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wasmerio / wasmer-js / packages / wasm-terminal / src / command-runner / command-runner.ts View on Github external
// Data Callback
      Comlink.proxy(
        this._processDataCallback.bind(this, {
          commandOptionIndex,
          sync: false
        })
      ),
      // End Callback
      Comlink.proxy(
        this._processEndCallback.bind(this, {
          commandOptionIndex,
          processWorker
        })
      ),
      // Error Callback
      Comlink.proxy(
        this._processErrorCallback.bind(this, { commandOptionIndex })
      ),
      // Shared Array Bufer
      sharedStdinBuffer,
      // Stdin read callback
      Comlink.proxy(this._processStartStdinReadCallback.bind(this))
    );

    // Initialize the shared Stdin.
    // Index 0 will be number of elements in buffer
    const sharedStdin = new Int32Array(sharedStdinBuffer);
    sharedStdin[0] = -1;

    return {
      process,
      commandOptionIndex,
github wasmerio / wasmer-js / packages / wasm-terminal / src / command-runner / command-runner.ts View on Github external
),
      // End Callback
      Comlink.proxy(
        this._processEndCallback.bind(this, {
          commandOptionIndex,
          processWorker
        })
      ),
      // Error Callback
      Comlink.proxy(
        this._processErrorCallback.bind(this, { commandOptionIndex })
      ),
      // Shared Array Bufer
      sharedStdinBuffer,
      // Stdin read callback
      Comlink.proxy(this._processStartStdinReadCallback.bind(this))
    );

    // Initialize the shared Stdin.
    // Index 0 will be number of elements in buffer
    const sharedStdin = new Int32Array(sharedStdinBuffer);
    sharedStdin[0] = -1;

    return {
      process,
      commandOptionIndex,
      worker: processWorker,
      sharedStdin: sharedStdin
    };
  }
github wasmerio / wasmer-js / examples / wapm-shell / services / command-runner / command-runner.ts View on Github external
if (
          commandOptionIndex <
          this.commandOptionsForProcessesToRun.length - 1
        ) {
          // Try to spawn the next process, if we haven't already
          this.tryToSpawnProcess(commandOptionIndex + 1);
        } else {
          // We are now done!
          // Call the passed end callback
          this.isRunning = false;
          this.endCallback();
        }
      }),
      // Error Callback
      Comlink.proxy((error: string) => {
        this.xterm.write(
          `Program ${this.commandOptionsForProcessesToRun[commandOptionIndex].args[0]}: ${error}\r\n`
        );
        this.kill();
        this.endCallback();
      }),
      // Stdin
      this.initialStdinDataForNextProcess.length > 0
        ? this.initialStdinDataForNextProcess
        : undefined,
      // Binary Script (Fallback case)
      this.isUsingFallback ? binaryenScript : undefined
    );

    // Remove the initial stdin if we added it
    if (this.initialStdinDataForNextProcess.length > 0) {
github wasmerio / wasmer-js / packages / wasm-terminal / src / command-runner / command-runner.ts View on Github external
const sharedStdinBuffer = new SharedArrayBuffer(8192);

    // Get our filesystem state
    const wasmFsJson = this.wasmTerminalConfig.wasmFs.toJSON();

    // Create our Io Device Window
    const ioDeviceWindow = new IoDeviceWindow();

    // @ts-ignore
    const process: any = await new processComlink(
      // Command Options
      this.commandOptionsForProcessesToRun[commandOptionIndex],
      // WasmFs File System JSON
      wasmFsJson,
      // Data Callback
      Comlink.proxy(
        this._processDataCallback.bind(this, {
          commandOptionIndex,
          sync: false
        })
      ),
      // End Callback
      Comlink.proxy(
        this._processEndCallback.bind(this, {
          commandOptionIndex,
          processWorker
        })
      ),
      // Error Callback
      Comlink.proxy(
        this._processErrorCallback.bind(this, { commandOptionIndex })
      ),
github wasmerio / wasmer-js / packages / wasm-terminal / src / command-runner / command-runner.ts View on Github external
// Data Callback
      Comlink.proxy(
        this._processDataCallback.bind(this, {
          commandOptionIndex,
          sync: false
        })
      ),
      // End Callback
      Comlink.proxy(
        this._processEndCallback.bind(this, {
          commandOptionIndex,
          processWorker
        })
      ),
      // Error Callback
      Comlink.proxy(
        this._processErrorCallback.bind(this, { commandOptionIndex })
      ),
      // Io Device Window
      Comlink.proxy(ioDeviceWindow),
      // Shared Array Bufer
      sharedStdinBuffer,
      // Stdin read callback
      Comlink.proxy(this._processStartStdinReadCallback.bind(this))
    );

    // Initialize the shared Stdin.
    // Index 0 will be number of elements in buffer
    const sharedStdin = new Int32Array(sharedStdinBuffer);
    sharedStdin[0] = -1;

    return {
github wasmerio / wasmer-js / packages / wasm-terminal / src / command-runner / command-runner.ts View on Github external
// @ts-ignore
    const process: any = await new processComlink(
      // Command Options
      this.commandOptionsForProcessesToRun[commandOptionIndex],
      // WasmFs File System JSON
      wasmFsJson,
      // Data Callback
      Comlink.proxy(
        this._processDataCallback.bind(this, {
          commandOptionIndex,
          sync: false
        })
      ),
      // End Callback
      Comlink.proxy(
        this._processEndCallback.bind(this, {
          commandOptionIndex,
          processWorker
        })
      ),
      // Error Callback
      Comlink.proxy(
        this._processErrorCallback.bind(this, { commandOptionIndex })
      ),
      // Io Device Window
      Comlink.proxy(ioDeviceWindow),
      // Shared Array Bufer
      sharedStdinBuffer,
      // Stdin read callback
      Comlink.proxy(this._processStartStdinReadCallback.bind(this))
    );
github wasmerio / wasmer-js / packages / wasm-terminal / src / command-runner / command-runner.ts View on Github external
// @ts-ignore
    const process: any = await new processComlink(
      // Command Options
      this.commandOptionsForProcessesToRun[commandOptionIndex],
      // WasmFs File System JSON
      wasmFsJson,
      // Data Callback
      Comlink.proxy(
        this._processDataCallback.bind(this, {
          commandOptionIndex,
          sync: false
        })
      ),
      // End Callback
      Comlink.proxy(
        this._processEndCallback.bind(this, {
          commandOptionIndex,
          processWorker
        })
      ),
      // Error Callback
      Comlink.proxy(
        this._processErrorCallback.bind(this, { commandOptionIndex })
      ),
      // Shared Array Bufer
      sharedStdinBuffer,
      // Stdin read callback
      Comlink.proxy(this._processStartStdinReadCallback.bind(this))
    );

    // Initialize the shared Stdin.
github casual-simulation / aux / src / aux-vm-browser / vm / AuxVMImpl.ts View on Github external
this._connectionStateChanged.next({
            type: 'progress',
            message: 'Creating VM...',
            progress: 0.2,
        });
        const wrapper = wrap(this._channel.port1);
        this._proxy = await new wrapper(
            location.origin,
            this._initialUser,
            this._config
        );

        let statusMapper = remapProgressPercent(0.2, 1);
        return await this._proxy.init(
            proxy(events => this._localEvents.next(events)),
            proxy(events => this._deviceEvents.next(events)),
            proxy(state => this._stateUpdated.next(state)),
            proxy(state =>
                this._connectionStateChanged.next(statusMapper(state))
            ),
            proxy(err => this._onError.next(err))
        );
    }
github casual-simulation / aux / src / aux-vm-browser / partitions / ProxyClientPartition.ts View on Github external
async init(): Promise {
        const proxies = [
            proxy((bots: Bot[]) => this._handleOnBotsAdded(bots)),
            proxy((bots: string[]) => this._handleOnBotsRemoved(bots)),
            proxy((bots: UpdatedBot[]) => this._handleOnBotsUpdated(bots)),
            proxy((error: any) => this._onError.next(error)),
            proxy((events: DeviceAction[]) => this._onEvents.next(events)),
            proxy((status: StatusUpdate) => this._onStatusUpdated.next(status)),
        ] as const;

        this._proxies = proxies;
        await this._bridge.addListeners(...proxies);
    }
github transcend-io / penumbra / src / workers.ts View on Github external
const setup = new Link().then(async (thread: PenumbraWorkerAPI) => {
    await thread.setup(proxy(reDispatchEvent));
  });
  await setup;

comlink

Comlink makes WebWorkers enjoyable

Apache-2.0
Latest version published 5 days ago

Package Health Score

82 / 100
Full package analysis

Similar packages