Promises instead callbacks. Now server not crashed if send bad token.#3
Closed
OsirisAnubiz wants to merge 2 commits into
Closed
Promises instead callbacks. Now server not crashed if send bad token.#3OsirisAnubiz wants to merge 2 commits into
OsirisAnubiz wants to merge 2 commits into
Conversation
tshemsedinov
requested changes
Mar 22, 2023
Member
tshemsedinov
left a comment
There was a problem hiding this comment.
Please make separate example in new folder instead changing callback-style code. For example move JavaScript to JavaScript/Callbacks and put this example to JavaScript/AsyncAwait
| callback(new Error('Invalid session token')); | ||
| return; | ||
| } | ||
| const safePath = (promise) => (token, ...args) => { |
Member
There was a problem hiding this comment.
promise is not an instance of Promise, it's an AsyncFunction so naming is confusing
| let data; | ||
| try { | ||
| data = await readSession(key); | ||
| } catch (err) { |
Author
There was a problem hiding this comment.
Would it be better to create 2 pull requests? First for fix crashing server. Second for async/await syntax.
Member
There was a problem hiding this comment.
It would be better to open separate PRs from different branches
Author
There was a problem hiding this comment.
Thank you. I will do as you said. I apologize for the inconvenience.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
storage.jsto promise (async/await).1.1. Now function
safePathtakes a promise as the first argument and return promise, instead callback contract.const safePath = (fn) => (token, ...args) => {const safePath = (promise) => (token, ...args) => {1.2. All methods in Storage async. This method await safePath promises.
async get(key) {data = await readSession(key);async save(key) {await writeSession(key, data);async delete(key) {await deleteSession(key);undefinedif not found file session.This makes Storage contract look more like Map contract(if not found return
undefined).3. Session.restore method
Now if you pass a bad token, the server will not crash.