Skip to content

A Map that internally manages async opening/closing of ready-resources

License

Notifications You must be signed in to change notification settings

mafintosh/ready-resource-map

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ready-resource-map

Manage collections of ready-resources keyed by IDs, ensuring that the same resource is never concurrently opened more than once.

Usage

const ReadyResourceMap = require('ready-resource-map')

const m = new ReadyResourceMap()

// r1 === r2
const [r1, r2] = await Promise.all([
  m.open('my-id', create),
  m.open('my-id', create)
])

m.close('my-id')
// Will wait for the above close to resolve before overwriting 'my-id'
const r3 = await m.open('my-id', create)

function create () {
  // MyResource extends ReadyResource
  return new MyResource()
}

License

MIT

About

A Map that internally manages async opening/closing of ready-resources

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages

  • JavaScript 100.0%