Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Refactor Status #135

Open
heineiuo opened this issue Jun 25, 2020 · 0 comments
Open

Refactor: Refactor Status #135

heineiuo opened this issue Jun 25, 2020 · 0 comments

Comments

@heineiuo
Copy link
Owner

heineiuo commented Jun 25, 2020

Status is just a wrapper for Promise

Current Status:

class Status {

async ok():Promise<boolean> {
    constructor(promise:Promise) {
this.promise  = promise
}

    try {
     await this.promise
     return true
    catch(e){
     return false
   }
 }
}

const status = new Status(promise)
if (await status.ok()) {
   // do stuff
}

refactor:

async function method(){
  let error:void|Error
  try {
      await promise
   } catch(e){
      error = e
   }

   return e
}

if (!(await method())) {
    // do stuff
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant