https://discord.cloudflare.com logo
Join Discord
Powered by
# workers-discussions
  • h

    HardAtWork

    04/23/2023, 12:51 PM
    Which docs were those?
  • s

    sathoro

    04/23/2023, 12:52 PM
    > When using the nodejs_compat compatibility flag in local development, you must use wrangler dev --experimental-local instead of wrangler dev --local. --experimental-local will soon become the default for local development in Wrangler.
  • s

    sathoro

    04/23/2023, 12:52 PM
    https://developers.cloudflare.com/workers/runtime-apis/nodejs/
  • s

    sathoro

    04/23/2023, 12:52 PM
    so yeah it was pretty clear about it 🤣
  • h

    HardAtWork

    04/23/2023, 12:52 PM
    Hm...
  • h

    HardAtWork

    04/23/2023, 12:53 PM
    Now I'm wondering if it will work...
  • s

    sathoro

    04/23/2023, 12:53 PM
    it is working now, but the my first attempt to store a value and retrieve it didn't work
  • h

    HardAtWork

    04/23/2023, 12:54 PM
    Yeah, then you might need
    --experimental-local
    after all. What OS are you on?
  • s

    sathoro

    04/23/2023, 12:55 PM
    I'm pretty confident it is my mistake, because I've never used AsyncLocalStorage before it is not clear how to simply store
    foo
    and then access it in another file
  • s

    sathoro

    04/23/2023, 12:55 PM
    Windows
  • s

    sathoro

    04/23/2023, 12:56 PM
    don't judge me
  • h

    HardAtWork

    04/23/2023, 12:57 PM
    That might be why.
    workerd
    was, until recently Unix(more like Ubuntu) only, and while a PR to add support to Windows was recently merged, there are probably still some issues to be ironed out...
  • s

    sathoro

    04/23/2023, 12:58 PM
    oh it looks like I need to wrap all my code inside
    run
    to access the storage
  • s

    sathoro

    04/23/2023, 12:59 PM
    ah I understand the docs a bit more now I think
  • s

    sathoro

    04/23/2023, 1:00 PM
    this is more complex than I was hoping, and I'm not sure if it will let me access a global variable from any file
  • s

    sathoro

    04/23/2023, 1:01 PM
    wouldn't I still need to pass around the
    asyncLocalStorage
    instance?
  • h

    HardAtWork

    04/23/2023, 1:03 PM
    You shouldn't need to
  • s

    sathoro

    04/23/2023, 1:03 PM
    wait, the storage isn't local to the request 😦
  • h

    HardAtWork

    04/23/2023, 1:04 PM
    Isn't that the whole point?
  • h

    HardAtWork

    04/23/2023, 1:05 PM
    The reason why they got rid of the whole "global bindings" thing was because it was slow, and required a full reboot of the isolate to use new bindings
  • s

    sathoro

    04/23/2023, 1:05 PM
    I guess I didn't specify explicitly, but no because Sentry has tons of configuration that is done per request
  • s

    sathoro

    04/23/2023, 1:05 PM
    I'm wanting request-local storage I can easily access
  • h

    HardAtWork

    04/23/2023, 1:05 PM
    Then I think you just have to pass it around manually
  • s

    sathoro

    04/23/2023, 1:07 PM
    but anyways when I do:
    Copy code
    const asyncLocalStorage = new AsyncLocalStorage();
    await asyncLocalStorage.getStore(); // undefined
    from an inner function (like a route), this just returns undefined. so I think you do need to pass around the original
    asyncLocalStorage
    instance
  • s

    sathoro

    04/23/2023, 1:07 PM
    or maybe I could expose a function to return it
  • s

    sathoro

    04/23/2023, 1:10 PM
    oh yeah this works:
    Copy code
    js
    const asyncLocalStorage = new AsyncLocalStorage();
    export const getLocalStorage = () => asyncLocalStorage.getStore();
    
    let idSeq = 0;
    
    export default {
      async fetch(request, env, context) {
        return asyncLocalStorage.run(idSeq++, async () => {
           ...
    second file:
    Copy code
    js
    import { getLocalStorage } from "../index";
    
    await getLocalStorage();
  • s

    sathoro

    04/23/2023, 1:12 PM
    not 100% sure on a use case though tbh, but could come in handy
  • m

    Murder Chicken

    04/23/2023, 1:30 PM
    The exact error is "Response closed due to connection limit" ... got that wrong.
  • k

    kian

    04/23/2023, 1:40 PM
    Are you reading the body of the responses?
  • k

    kian

    04/23/2023, 1:40 PM
    If not, they will stay open and contribute to the limit.
1...241124122413...2509Latest