Skip to content

Atomicly SetIfAbsent #54

@lwahlmeier

Description

@lwahlmeier

Is there anyway to atomicly set a value if one does not already exist?

I have tried a couple different things and they don't seem to work for my use case, I have examples if wanted:

  • CompareAndSwap(key, nil, value) which doesn't seem to work on unset keys.
  • GetOrSet and GetOrCompute but those don`t seem to be threadsafe.

If there is currently no way to do this would you be open to a PR adding it?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions