Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/async storage #94

Merged
merged 1 commit into from
Apr 14, 2023
Merged

Feature/async storage #94

merged 1 commit into from
Apr 14, 2023

Conversation

ptoussai
Copy link
Contributor

@ptoussai ptoussai commented Apr 6, 2023

No description provided.

@lehni lehni force-pushed the master branch 2 times, most recently from f3f4ac1 to d0fbf55 Compare April 13, 2023 15:08
get transaction() { return ctx.transaction },
get logger() { return ctx.logger }
},
() => next()
Copy link
Contributor

@lehni lehni Apr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can just be next, no need to wrap a function in a function ;)

Object.defineProperties(app, {
requestLocalStorage: { value: requestLocalStorage },
locals: { get() { return requestLocalStorage.getStore() ?? {} } }
})
Copy link
Contributor

@lehni lehni Apr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename these:

requestStorage
requestLocals

And let's move the defineProperties() monkey-patching to the Application class properly:

constructor(...) {
   this.requestStorage = new AsyncLocalStorage()
   ...
}

get requestLocals() {
  return this.requestStorage.getStore() ?? {}
}

@@ -0,0 +1,17 @@
import { AsyncLocalStorage } from 'async_hooks'

export function setupRequestLocalStorage(app) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just setupRequestStorage() then

@lehni lehni force-pushed the master branch 2 times, most recently from 19cd9f1 to 8c14378 Compare April 14, 2023 09:07
@lehni lehni merged commit 4ebef91 into master Apr 14, 2023
@lehni
Copy link
Contributor

lehni commented Apr 14, 2023

@ptoussai great, thanks!

@lehni lehni deleted the feature/async-storage branch April 14, 2023 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants