Open aminya opened 4 years ago
@stevenvachon Could you check this?
Some tests for the promises, please.
@stevenvachon I added the tests, types, and documentation. Note that this should be a major release due to changing the API.
Oh, I thought this added promises, but you actually removed the callback. I'd prefer it if it supported both. But if it's better to drop callbacks, I think it's better to write as promises instead of wrapping with util.promisify
.
Oh, I thought this added promises, but you actually removed the callback. I'd prefer it if it supported both. But if it's better to drop callbacks, I think it's better to write as promises instead of wrapping with
util.promisify
.
Promisify automatically removes callbacks and adds promises. This way we don't need to change all the code. So, I have added promises here.
If you want, we can export _get, _set to support the old behavior.
I'd rather have a function that accepts a callback and returns a promise.
I'd rather have a function that accepts a callback and returns a promise.
What's the point of returning a Promise when we have callbacks? The whole point of Promise is to await it any time we like and run our callback anytime we want. Callbacks should be avoided, that's old JavaScriptism which has ruined a lot of codebases. That's why Node made promisify
.
Not everyone uses promises. The fs
lib still defaults to callbacks too and this lib was created to resemble core Node.js modules.
Not everyone uses promises. The
fs
lib still defaults to callbacks too and this lib was created to resemble core Node.js modules.
Those that don't use callback can always use then(()=>{})
, but the opposite is not possible. You can't await a non-promisified callback-based function.
The only reason I made this PR was to remove callbacks. If this is this library wants to go towards this path, I prefer to make a new promisified library that ditches callbacks.
const func = callback => new Promise((resolve, reject) => {
_func((error, result) => {
if (callback) {
callback(error, result);
} else if (error != null) {
reject(error);
} else {
resolve(result);
}
});
};
func((error, result) => {});
func().then(result => {});
Anyone who wants this PR, I have registered it under a new name:
npm install @aminya/winattr
Closes #9
If you want this:
Install the package: