phetsims / paper-land

Build and explore multimodal web interactives with pieces of paper!
https://phetsims.github.io/paper-land/
MIT License
10 stars 1 forks source link

DOn't write to characteristic if write is already in progress #244

Closed jessegreenberg closed 10 hours ago

jessegreenberg commented 2 weeks ago

boardBluetoothServers.writeToCharacteristic has this:

  async writeToCharacteristic( serviceUUID, characteristicUUID, value ) {

    // If we are already trying to write to this characteristic, don't make another request.
    if ( this.characteristicIdToProgressMap.has( characteristicUUID ) ) {
      return;
    }

    this.characteristicIdToProgressMap.set( characteristicUUID, true );

    const characteristic = await this.getServiceCharacteristic( serviceUUID, characteristicUUID );
    characteristic.writeValue( value );

    // After the await, the write is complete.
    this.characteristicIdToProgressMap.delete( characteristicUUID );
  }

But it would be better if writeToCharacteristic were not called at all if the write is in progress. This will prevent the "GATT operation already in progress errors" that we are currently seeing.

jessegreenberg commented 10 hours ago

I am not sure what I was thinking before, but whether you return early or prevent calling the function at all would be the same. I haven't seen the GATT operation already in progress errors and wonder if it was fixed by something else. Closing.