https://discord.cloudflare.com logo
Join Discord
Powered by
# durable-objects
  • l

    lukeed

    08/14/2021, 1:18 AM
    thats not true either; its just much easier to add 1 utility function to 3 years worth of framework/projects than it is to go thru the rabbitholes & add/update parameters for nearly every utility function
  • l

    lukeed

    08/14/2021, 1:19 AM
    modules ftw, but grabbing
    waitUntil
    from X instead of from Y serves no benefit to me
  • e

    Erwin

    08/14/2021, 1:21 AM
    But.. back to the AssetHandler, I think it would actually be a pretty good solution
  • l

    lukeed

    08/14/2021, 1:25 AM
    cuz it addresses the same thing all/most other utilities are gunna face
  • l

    lukeed

    08/14/2021, 1:25 AM
    aka, all my project code. thats why im gunna be doing it everywhere
  • e

    Erwin

    08/14/2021, 1:26 AM
    So you would import the module version of KV and it would assemble the FetchEvent and call the "regular" handler?
  • l

    lukeed

    08/14/2021, 1:29 AM
    module version of KV?
  • e

    Erwin

    08/14/2021, 1:37 AM
    For your solution you would need to have a separate import if you want to run modules right?
  • l

    lukeed

    08/14/2021, 1:42 AM
    I personally would prefer that the KV binding were always passed in. A separate export could avoid the need for new major version, but if major is on the table, then (event, option.binding) pair would work for both fairly easily. The breaking change would just be that option is a binding and not a string
  • m

    mikeysee

    08/14/2021, 8:39 AM
    Is there a way to get the ID of the durable object from within the object itself?
  • m

    MrBBot

    08/14/2021, 9:44 AM
    yep, you can get it from the
    state
    parameter passed to the constructor: https://developers.cloudflare.com/workers/runtime-apis/durable-objects#durable-object-class-definition
    Copy code
    js
    export class DurableObject {
      constructor(state, env){
        this.id = state.id;
      }
    
      async fetch(request) {
        return new Response(this.id.toString());
      }
    }
  • m

    mikeysee

    08/14/2021, 9:58 AM
    ah, awesome thranks 🙂
  • m

    mikeysee

    08/14/2021, 10:05 AM
    Suppose we have a scenario that a user calls a worker, that worker than calls a DurableObject which wants to perform some long running operation. If the user reloads their tab before the long running operation has finished what will happen?
  • m

    MrBBot

    08/14/2021, 10:06 AM
    good question, not so sure 😕
  • m

    mikeysee

    08/14/2021, 10:07 AM
    Ye.. I kind of need a way to trigger an operation that might take some time such as sending an email or uploading a file somewhere for example. If that operation is cancelled because the user reloaded their tab thats not good
  • w

    Walshy | Pages

    08/14/2021, 10:08 AM
    I assume it would just keep running. The Worker doesn't know they reloaded unless there was like a websocket.
  • m

    mikeysee

    08/14/2021, 10:09 AM
    Ah okay I thought I read somewhere that it terminates
  • w

    Walshy | Pages

    08/14/2021, 10:10 AM
    I don't know for sure, you should probably test, I'm just assuming
  • m

    mikeysee

    08/14/2021, 10:10 AM
    Perhaps it terminates if the connection from the worker to the DO terminates?
  • d

    Deleted User

    08/14/2021, 10:32 AM
    anyone have a nice way to use the transactional storage API from the worker (rather than the DO)?
  • i

    ItsWendell

    08/14/2021, 12:00 PM
    @Deleted User I don't think the worker has a transactional storage API. I have a Durable Object that acts as a REST API and an Client in the worker that acts like the storage API from the DO's, but the only thing that doesn't support yet is transactions.
  • d

    Deleted User

    08/14/2021, 12:12 PM
    er, right, bad wording
  • d

    Deleted User

    08/14/2021, 12:13 PM
    so the problem is i definitely need to somehow access the transactional api from the worker
  • d

    Deleted User

    08/14/2021, 12:13 PM
    of course, given that there is no transactional api on the stub itself, you'd probably need to serialize it somehow
  • d

    Deleted User

    08/14/2021, 12:14 PM
    i wonder if a custom HTTP method would be a bad idea...
  • i

    ItsWendell

    08/14/2021, 12:23 PM
    Yeah that could be tricky, since you'd probably want to read and write within an transaction based on the read that you do.
  • d

    Deleted User

    08/14/2021, 12:24 PM
    ya
  • i

    ItsWendell

    08/14/2021, 12:25 PM
    If it's an increment for an number for example, you can probably write something for that.
    /increment?key=counter:ID&amount=43221
  • i

    ItsWendell

    08/14/2021, 12:26 PM
    Than do the read + write in an transaction that increments that.
  • d

    Deleted User

    08/14/2021, 12:26 PM
    the problem, of course
1...152153154...567Latest