public async run()

in sdklab/stress_fault/src/stress_fault.ts [77:114]


  public async run(): Promise<void> {
    // Create a device instance
    const description = await deviceIdentityHelper.createDeviceWithSymmetricKey();
    this.deviceId = description.deviceId;
    this.objectName = description.deviceId;

    let tasks = [];
    try {
      // Create the client and connect.
      this.client = Client.fromConnectionString(description.connectionString, protocol);
      await this.client.open();

      // Spin up tasks for operations to run at various intervals.
      tasks = [
        this._runAtInterval(this._send.bind(this), D2C_SEND_INTERVAL),
        this._runAtRandomInterval(this._fault.bind(this), FAULT_INTERVAL_MIN, FAULT_INTERVAL_MAX),
      ];

      // Wait for one of the sub-tasks to fail or complete.
      await Promise.race(tasks);
    } catch (e) {
      debugErrors(`Exception: ${e}`);
      throw e;
    } finally {
      debug('One device task exited.  Stopping device');
      this.done = true;
      try {
        if (tasks) {
          await (Promise as any).allSettled(tasks);
        }
      } finally {
        debug('finally');
        await this.client.close();
        await deviceIdentityHelper.deleteDevice(this.deviceId);
        debug('device deleted');
      }
    }
  }