Are you executing that in the global
Are you executing that in the global scope by any chance, rather than in the event handler?
2 Replies
yep, that was the issue. but question is why is it like that
https://stackoverflow.com/a/58491358
The reason for this is that Cloudflare Workers runs the global scope at an unspecified time. It might be on-demand when a request arrives, but it could be earlier. In theory, Workers could even execute the global scope only once ever, and then snapshot the state and start from the snapshot when executing on the edge. In order to ensure that such different implementation options do not affect the behavior of deployed workers, the Workers Runtime must ensure that the global scope's execution is completely deterministic. Among other things, that means Date.now() must always return the same value -- zero -- when executed at the global scope.