Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const getAllPropertyNames = require('./get_all_property_names'),
- Mutex = require('./mutex')
- function actor(object) {
- let methods = getAllPropertyNames(object),
- mutex = new Mutex(),
- wrapper = {}
- for (let method of methods) {
- if (typeof object[method] !== 'function') continue
- wrapper[method] = actorMethodDescriptor(mutex, object, method)
- }
- return Object.create(object, wrapper)
- }
- function actorMethodDescriptor(mutex, object, method) {
- return {
- value: (...args) => {
- return mutex.synchronize(() => object[method](...args))
- }
- }
- }
- module.exports = actor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement