We’re rewarding the question askers & reputations are being recalculated! Read more.

New answers tagged

2

Well, generally it is not a problem to call a sync method within async method. You are actualy doing this in more then few instances (GetExtension, NewGuild, ToString, etc...) But if you have an async method available it would be shame to not use it. Which you have - IFormFile.CopyToAsync(). using (var bits = new FileStream(path, FileMode.Create)) { ...


2

Some suggestions: Since this is an async function, it seems likely the caller may want to know when it's done and if it succeeded. To do that, you need to reject upon error. That means rethrow after logging inside your catch. This allows the error to get back to the caller as a rejected promise. Simplify by changing config.archives.reduce() to config....


3

Tips for JS code optimization: Variable names Give your variables meaningful names: const r1 = await dialog.showOpenDialog(...) can be renamed to dirs or dirList (representing selected directories) const r2 = await fsp.readFile('./config.json', 'utf8'), config = JSON.parse(r2), where r2 is supposed to be a config file path. Let's rename it to say const ...


2

Parent-less class class TokenBucket(): can drop the parens. lower_snake_case These variables: tokensPerS refillSleepS sleepDuration etc., and all of your methods, should be in lower_snake_case instead of camelCase, by convention. Type hints PEP484 allows you to turn this def hasTokens(self): into this def hasTokens(self) -> bool: and likewise ...


Top 50 recent answers are included