logo
down
shadow

Typescript chaining Promises


Typescript chaining Promises

By : Huan Pham
Date : November 20 2020, 11:01 PM
With these it helps The error is due to the fact that you try to change the type of dbPromise.
When it is first declared:
code :
let dbPromise = isBrowser()
      .then(browser => {
        const openDatabase = browser ? openBrowserDatabase : openCordovaDatabase;
        return openDatabase(name);
      });
dbPromise = _db.execute(sql)
let dbPromise: Promise<any> = ...


Share : facebook icon twitter icon
ES6 promises, chaining promises only if previous promises were rejected, while keeping rejection reasons

ES6 promises, chaining promises only if previous promises were rejected, while keeping rejection reasons


By : JinJian_
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I believe you can do it like this (where auth1, auth2, and auth3 are the auth functions returning promises):
code :
auth1(/*args*/)
    .catch(failed => auth2(/*args*/))
    .catch(failed => auth3(/*args*/))
    .then(result => {
      console.log("Success:" + result);
      return result;
    })
    .catch(failed => {
      console.log("Failure:" + failed);
    });
let failures = [];
auth1(/*args*/)
    .catch(failed => {failures.push(failed); return auth2(/*args*/);})
    .catch(failed => {failures.push(failed); return auth3(/*args*/);})
    .then(result => {
      console.log("Success: " + result + " (failed: " + failures.join(", ") + ")");
      return result;
    })
    .catch(failed => {
      failures.push(failed);
      console.log("Failures: " + failures.join(", "));
    });
let auths = [auth1.bind(null, /*args*/), auth2.bind(null, /*args*/), auth3.bind(null, /*args*/)];
return auths.reduce((p, auth) => p.catch(failed => auth()), Promise.reject())
    .then(result => {
      console.log("Success: " + result);
      return result;
    })
    .catch(failed => {
      console.log("Failed: " + failed);
    });
confusion about chaining $q promises with angular and typescript

confusion about chaining $q promises with angular and typescript


By : weirdococo
Date : March 29 2020, 07:55 AM
I hope this helps you . I'm pretty inexperienced with Q, promises, angular, and typescript - so it seemed the obviously intelligent choice was to try using them all together! , Just return the promise from the inner function like this:
code :
$articles.Fetch(1).then((r: IArticleRequestData) => {
    return $articles.Clear()
}).then((l:any)=> {
    // occurs after everything else is done and inner
    // functions are finished
});
Chaining ES6 Promises in Mongoose with Typescript

Chaining ES6 Promises in Mongoose with Typescript


By : Amir Abbas Kashani
Date : March 29 2020, 07:55 AM
hop of those help? Add control flow to the existing user by using a existing flag on the promise's response. Example:
code :
public static signup(req: express.Request, res: express.Response) {
      UserModel.findOne({ email: req.body.email }).exec()
      .then(existingUser => {
          if(existingUser) {
              return Promise.resolve({
                user: existing,
                existing: true
              });
          }
          return UserModel.create({
              firstName: req.body.firstName,
              lastName: req.body.lastName,
              email: req.body.email,
              password: req.body.password
          }).then((user) => {
            return Promise.resolve({
              existing: false,
              user: user
            });
          });
      })
      .then(response => {
        if (response.existing) {
          return res.send({ message: `Email ${response.user.email} is in use` });
        } else return res.send({ token: AuthUtils.createJWT(response.user)});
      })
      .catch(err => {
          console.log(err);
      });
  }
Chaining Promises in Typescript

Chaining Promises in Typescript


By : Bogdan Brezuica
Date : March 29 2020, 07:55 AM
wish of those help awaits become then calls - often nested ones for scoping and control flow to be effective - and loops become recursion. In your case:
code :
(function loop(lib, sum, lastValue){
    if (sum > 0) {
        console.log(`${sum} left`);
        return lib.isA().then(res => {
            if (res) {
                console.log("Do A()");
                return lib.opA().then(lastValue => {
                    sum -= lastValue;
                    return loop(lib, sum, lastValue);
                });
            } else {
                console.log("Do B()");
                return lib.opB(lastValue).then(lastValue => {
                    sum -= lastValue*3;
                    return lib.isC().then(res => {
                        if (res) {
                            console.log("Do C()");
                            return lib.opC().then(res => {
                                sum += res;
                                return loop(lib, sum, lastValue);
                            });
                        }
                        return loop(lib, sum, lastValue);
                    });
                });
            }
        });
    } else {
        console.log("All completed!");
        return Promise.resolve()
    }
})(new Service(), 20, 0);
Chaining promises in ES6/Typescript

Chaining promises in ES6/Typescript


By : H.soni
Date : March 29 2020, 07:55 AM
I wish this help you You can extract the json data you want from the responses and send them to the next promise by mapping over them:
code :
activate() {
    return Promise.all([
        this.http.fetch('photos'),
        this.http.fetch('photos2')
    ]).then(responses => {

        // this will send the actual json data 
        // you want to the next chained promise
        return responses.map(response => response.json())

    }).then(data => {

        // data is now an array of the the json objects 
        // you are trying to get from the requests
        console.log(data);
        this.photos = data;

    }).catch(err => {
        console.log(err);
    });
}
Related Posts Related Posts :
  • Enumerate properties on an object
  • How to change language mode of VSCode programmatically?
  • Storing generic object in private property on class
  • Aurelia CLI + Typescript: Cannot find module errors
  • Protractor Get Text of Notification
  • In Typescript how to Ignore NPM package's built-in declaration file?
  • Difference beetween an array-of-type definition and type-in-array definition
  • What is the shortcut in Visual Studio Code for console.log
  • TypeScript checking front-end template files
  • Instruct to typescript that a class assigns properties dinamically
  • commands not working properly in VS Code integrated terminal (Bash)
  • Not able to read the step definitions files of Protractor cucumber e2e tests
  • typescript how to combine two objects to an array
  • Typescript Definitions Modification
  • TS 2322 - Property 'id' is missing in type '{ id: number
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com