Closed Gozala closed 2 years ago
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.