小编Sau*_*dav的帖子

Wait the end of a function before to start the next

I'm working on Ionic v4 with Angular.

In my project i use the BLE to communicate with a raspberry.

I have several step :

  1. Search Device around me
  2. Connect to this device
  3. Activate Notification
  4. Send Messages

Currently i have something like :

this.ble.scan().subscribe(result => {
  if (device === theDeviceIWant) {
    this.ble.connect(device.id).subscribe(result => {
      this.ble.startNotification(infosaboutDevice).subscribe(result => {
        // Message 1
        this.ble.writeWithoutResponse(infos, message).then(result => {
          // Message 2
          this.ble.writeWithoutResponse(infos, message).then(result => { 
            // Message 3
            this.ble.writeWithoutResponse(infos, message).then(result => {
              // Message X …
Run Code Online (Sandbox Code Playgroud)

javascript async-await ionic-framework es6-promise angular

3
推荐指数
1
解决办法
78
查看次数