You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I find strictly async interface for MultihashHasher to be problematic as it induces asynchrony even when that is impractical (from performance and API point of view). My specific use case is related to HAMT implementation which uses murmur3 that is non cryptographic hash and really doesn't need to be async, not to mention that actual implementation is sync. More generally, I think it would be reasonable to have an API that:
Provides general async API that can be used across implementations
Allows hasher user to conditionally avoid await at expense of increased code complexity.
Allows certain functions to demand Sync API as needed.
I propose to amend current interface definition as follows:
exportinterfaceMultihashHasher{/** * Takes binary `input` and returns it (multi) hash digest. * @param {Uint8Array} input */digest(input: Uint8Array): MultihashDigest|Promise<MultihashDigest>/** * Name of the multihash */name: string/** * Code of the multihash */code: number}exportinterfaceSyncMultihashHasherextendsMultihashHasher{digest(input: Uint8Array): MultihashDigest}
This way
All existing MultihashHasher implementations are compatible as MultihashHasher just widened return type of digest function.
All users of MultihashHasher can continue using await or choose to do so if return type is a promise.
Some implementations could switch to SyncMultihashHasher while retaining compatibility with all the existing code.
The text was updated successfully, but these errors were encountered:
yep, I agree and have thought about this previously - I've started defining and using a MaybePromise<T> elsewhere for the same reason and it's quite usable - by default you can await everything but where perf matters you can check what you're getting; and the SyncMultihashHasher would give an extra option for feature detection, so +1 to that.
I find strictly async interface for
MultihashHasher
to be problematic as it induces asynchrony even when that is impractical (from performance and API point of view). My specific use case is related toHAMT
implementation which uses murmur3 that is non cryptographic hash and really doesn't need to be async, not to mention that actual implementation is sync. More generally, I think it would be reasonable to have an API that:hasher
user to conditionally avoidawait
at expense of increased code complexity.Sync
API as needed.I propose to amend current interface definition as follows:
This way
MultihashHasher
implementations are compatible asMultihashHasher
just widened return type ofdigest
function.MultihashHasher
can continue usingawait
or choose to do so if return type is a promise.SyncMultihashHasher
while retaining compatibility with all the existing code.The text was updated successfully, but these errors were encountered: