Skip to content
This repository has been archived by the owner on Aug 24, 2021. It is now read-only.

feat: change api to async/await #37

Merged
merged 6 commits into from
Apr 16, 2019
Merged

feat: change api to async/await #37

merged 6 commits into from
Apr 16, 2019

Conversation

hugomrdias
Copy link
Member

BREAKING CHANGE: callbacks are not supported!!

benchmarks/hash.js Outdated Show resolved Hide resolved
Copy link
Member

@vmx vmx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working with Promises I always find it hard to make sure errors are really bubbled up correctly. Could you please add more tests for failure scenarios? It seems a bit hard to do as the hashing won't fail in many reasons, but at least one case I could think of is using a non supported hash function. Perhaps you could think of more cases.

As the API is so small it would be great if you could expand the BREAKING CHANGE notice on the commit message with an example on how the API changes. I think we should do this for all breaking changes, so that the changelog contains the upgrade path if you want to use the new version.

LICENSE Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
Copy link
Member

@alanshaw alanshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In summary, there's no reason to use new Promise unless we're converting a callback API and we should always use async/await over .then - there's no reason not to.

src/blake.js Show resolved Hide resolved
src/crypto.js Outdated Show resolved Hide resolved
src/index.js Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
src/sha.browser.js Show resolved Hide resolved
src/sha.js Show resolved Hide resolved
@daviddias
Copy link
Member

Really great review, @alanshaw 👏🏽👏🏽👏🏽 Lot's of knowledge shared on how to better use async/await. Thank you :)

@dirkmc dirkmc mentioned this pull request Mar 12, 2019
hugomrdias pushed a commit that referenced this pull request Mar 14, 2019
Address comments on [parent PR](#37)
hugomrdias pushed a commit that referenced this pull request Mar 14, 2019
Address comments on [parent PR](#37)
Copy link
Member

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just a super minor detail

list.push(res)
d.resolve()
})
multihashing(buf, alg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this to use await instead?

Copy link
Member

@alanshaw alanshaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

sha.sha2256((Buffer.from(firstHash)), cb)
})
default:
throw new TypeError(`${algorithm} is not a supported algorithm`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be a regular Error...

return Buffer.from(await crypto.subtle.digest({ name: 'SHA-256' }, d))
}
default:
throw new TypeError(`${algorithm} is not a supported algorithm`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regular Error?

src/sha.js Outdated
return crypto.createHash('sha256').update(first).digest()
}
default:
throw new TypeError(`${algorithm} is not a supported algorithm`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regular Error?

@alanshaw
Copy link
Member

alanshaw commented Apr 1, 2019

Lets get this released @hugomrdias!

@hugomrdias hugomrdias merged commit 01f1da6 into master Apr 16, 2019
@ghost ghost removed the status/in-progress In progress label Apr 16, 2019
@hugomrdias hugomrdias deleted the feat/async-iterators branch April 16, 2019 14:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants