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

    avi

    03/28/2023, 11:30 PM
    ahhh gotcha
  • w

    Walshy | Pages

    03/28/2023, 11:30 PM
    (Offtoptic but can't wait for crypto.createHmac)
  • k

    kian

    03/28/2023, 11:30 PM
    That's the one I see the most people try to port to WebCrypto
  • k

    kian

    03/28/2023, 11:30 PM
  • w

    Walshy | Pages

    03/28/2023, 11:31 PM
    I don't know why Web Crypto is such a pain to use
  • w

    Walshy | Pages

    03/28/2023, 11:31 PM
    Node had very nice APIs
  • k

    kian

    03/28/2023, 11:32 PM
    CryptoKey bindings will be nice if they follow mTLS certs
  • k

    kian

    03/28/2023, 11:32 PM
    where you upload it (a la secrets) w/ wrangler and reference it by name
  • a

    avi

    03/28/2023, 11:34 PM
    Copy code
    ts
    export class Counter {
      constructor() {
        setInterval(this.tick.bind(this), 1000);
      }
    
      async tick() {
        await scheduler.wait(1);
        const now = Date.now();
        console.log(now);
      }
    
      async fetch() {
        return new Response('Hello, world!');
      }
    }
  • a

    avi

    03/28/2023, 11:34 PM
    no dice
  • a

    avi

    03/28/2023, 11:35 PM
    Date.now()
    still frozen despite calling
    scheduler.wait(1)
  • a

    avi

    03/28/2023, 11:39 PM
    any ideas?
  • a

    avi

    03/28/2023, 11:41 PM
    neither of these work actually
  • u

    Unsmart | Tech debt

    03/28/2023, 11:41 PM
    The timer is supposed to have inaccuracy
  • k

    kian

    03/28/2023, 11:41 PM
    Assuming this is a DO, I can't comment on how time works there
  • a

    avi

    03/28/2023, 11:41 PM
    i'm not concerned about inaccuracy. the timer simply never advances.
  • a

    avi

    03/28/2023, 11:41 PM
    yes, it's a DO
  • k

    kian

    03/28/2023, 11:42 PM
    Copy code
    ts
    export default {
      async fetch() {
        const start = Date.now()
        await scheduler.wait(1)
        const end = Date.now()
    
        return new Response(`scheduler: ${end - start}`)
      }
    }
  • k

    kian

    03/28/2023, 11:42 PM
    This is all I've ever used in the past
  • u

    Unsmart | Tech debt

    03/28/2023, 11:42 PM
    It does eventually it shouldn't ever be off by more than 2 seconds
  • k

    kian

    03/28/2023, 11:42 PM
    DO timing has it's own quirks iirc
  • a

    avi

    03/28/2023, 11:42 PM
    oh, that's in a fetch()
  • a

    avi

    03/28/2023, 11:43 PM
    i'm doing this in a
    setInterval
  • a

    avi

    03/28/2023, 11:43 PM
    it does not ever advance
  • k

    kian

    03/28/2023, 11:43 PM
    What is
    now
    showing, a frozen timestamp or
    0
    ?
  • a

    avi

    03/28/2023, 11:43 PM
    here's the full code, you can give it a spin yourself:
    Copy code
    ts
    export default {
      async fetch(req: Request, env: any) {
        let id = env.COUNTER.idFromName('A');
        let obj = env.COUNTER.get(id);
        return obj.fetch(req);
      },
    };
    
    export class Counter {
      constructor() {
        setInterval(this.tick.bind(this), 1000);
      }
    
      async tick() {
        const start = Date.now();
        await scheduler.wait(1);
        const end = Date.now();
    
        console.log(`scheduler: ${end - start}ms`);
      }
    
      async fetch() {
        return new Response('Hello, world!');
      }
    }
  • a

    avi

    03/28/2023, 11:43 PM
    this prints:
    scheduler: 0ms
    forever
  • u

    Unsmart | Tech debt

    03/28/2023, 11:44 PM
    Is this a deployed worker?
  • a

    avi

    03/28/2023, 11:44 PM
    i'm running it locally
  • u

    Unsmart | Tech debt

    03/28/2023, 11:44 PM
    Oh ok well it's probably a bug in local
1...236523662367...2509Latest