Skip to content

Implement multiple locks at the same time. #3

@martinheidegger

Description

@martinheidegger

Right now, require('flexlock/createLocker') only allows a single key to lock towards lock(key, ...) but some code requires multiple resources to work, a new API that works like lock([keyA, keyB], ...) would be good. The obvious implementation would be to just use Promise.all to await three locks, but a more-complex implementation that allows other sublocks to receive early might be not a bad idea. In an example:

  1. (A) lock(['users', 'user:11'], ...) → ... processing
  2. (B) lock(['users', 'user:12'], ...) → ... waiting for (A) to finish
  3. (C) lock('user:12') → processing
  4. (A) finished, (B) → waiting for (C) to finish
  5. (C) finished, (B) → processing
  6. (B) finished

In that example (C) can start processing without waiting for (B) to finish because it only uses part of the resources of (B). This would require a more complicated implementation though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions