Node.js client for Google Cloud Storage: unified object storage for developers and enterprises, from live data serving to data analytics/ML to data archiving.
Currently we utilize @google-cloud/promisify in numerous files to create functions and methods that handle both callback and Promises APIs. The problem with this approach is that it's difficult to determine when something is promisified on the type-level and it makes debugging/understanding the codebase a bit more cumbersome (it can come off as 'magic' for newcomers).
Going forward, we should handle the logic directly in the methods - in a seamless way when possible.
Idea: Perhaps have an internal/privatePromise-only (async/await) version of methods, and have the public methods internally handling all difference between callback and Promise (e.g. most logic would be in the internalized-async/await function).
Currently we utilize
@google-cloud/promisify
in numerous files to create functions and methods that handle both callback and Promises APIs. The problem with this approach is that it's difficult to determine when something is promisified on the type-level and it makes debugging/understanding the codebase a bit more cumbersome (it can come off as 'magic' for newcomers).Source: https://github.com/googleapis/nodejs-storage/blob/a9c4c182827e221ad7324d0664e2a3c2fa72c41c/src/file.ts#L4121-L4130
Example (difficult to understand how a
Promise
is returned):https://github.com/googleapis/nodejs-storage/blob/a9c4c182827e221ad7324d0664e2a3c2fa72c41c/src/file.ts#L1532-L1676
Going forward, we should handle the logic directly in the methods - in a seamless way when possible. Idea: Perhaps have an internal/
private
Promise
-only (async/await
) version of methods, and have thepublic
methods internally handling all difference between callback andPromise
(e.g. most logic would be in the internalized-async/await
function).