Skip to content

Conversation

@KaylaNguyen
Copy link
Collaborator

No description provided.

@KaylaNguyen KaylaNguyen requested review from squee1945 and zevdg August 31, 2021 19:38
@zevdg
Copy link
Collaborator

zevdg commented Sep 24, 2021

IIUC, we consider user-specified unique keys to be strictly better than the automagic uniqueness we provided in gen1, because filename changes causing disruptions in delayed funcs was unexpected and confusing. Is that correct? If so, the new UX should do the right thing by default, and we should make it hard to accidentally do the wrong thing. This change does neither, it only allows people to go out of their way to do the right thing.

Did you consider just making a new function e.g. delay.Do(...) (or something like that) that effectively replaces delay.Func(...) but treats the key as unique? We can document delay.Do this as the new well lit path, and mark delay.Func as deprecated.

This is what I'd recommend because it

  1. it doesn't break existing code.
  2. new code will do the right thing by default without needing to remember to add a special prefix.
  3. if you're using a linter like staticcheck, you'll get warned if you try to do the wrong thing.

@squee1945
Copy link
Collaborator

I like this suggestion; it could be built on top of what is already here (and the UniqueKey could be made internal).

@squee1945
Copy link
Collaborator

Re: naming. Probably something like delay.Define or delay.Declare or delay.Register since this isn't the actual call to the function.

@zevdg
Copy link
Collaborator

zevdg commented Sep 24, 2021

agreed on naming. delay.Do does sound like it might be invoked immediately, which it definitely is not. I like all your suggestions. If we want to keep it a noun to mirror delay.Func, then something like delay.Action or delay.Execution would work too.

@KaylaNguyen
Copy link
Collaborator Author

I added Register function. Is this more aligned with what you're discussing? I'm not sure if we'll need unique key prefix for this but I can also be missing something.

Tests are failing due to b/200817325 but passing locally.

@squee1945
Copy link
Collaborator

LGTM.

The likelihood of colliding the user specified key with the package-based key seems very, very low. Likely don't need the unique: prefix.

@zevdg
Copy link
Collaborator

zevdg commented Sep 30, 2021

Agreed. Allowing the overlap is arguably a useful feature. It makes it possible to migrate from the Func to Register without changing the key in the process. Someone could write a tool that safely migrates code en-mass from the old function to the new one, which is a really nice property.

@KaylaNguyen KaylaNguyen requested review from squee1945 and zevdg October 5, 2021 00:42
@KaylaNguyen KaylaNguyen changed the title Allow users specify unique keys to use in delay pkg. Let users specify unique function keys using delay.Register Oct 7, 2021
@KaylaNguyen KaylaNguyen changed the title Let users specify unique function keys using delay.Register Let users specify unique function keys using delay.MustRegister Oct 12, 2021
@squee1945
Copy link
Collaborator

LGTM. Just some minor things.

Copy link
Collaborator

@zevdg zevdg left a comment

Choose a reason for hiding this comment

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

LGTM pending outstanding comments. Will approve once they're all resolved.

@KaylaNguyen KaylaNguyen requested a review from squee1945 October 27, 2021 20:24
@zond
Copy link

zond commented Oct 27, 2021

Great PR!

Thank you for making the world better by removing error prone magic in favor of explicitness.

Copy link
Collaborator

@zevdg zevdg left a comment

Choose a reason for hiding this comment

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

Nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

delay: Function key generation is obscure and need to be documented

5 participants