Created
June 13, 2022 06:05
-
-
Save kriskowal/695139991347a5dec676d54579032d8a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mutex = Promise.resolve(); | |
const protocol = { | |
command() { | |
const result = mutex.then(() => { | |
// mutual exclusion | |
}); | |
mutext = next.catch(() => {}); | |
return result; | |
}, | |
close() { | |
mutex = mutex.then(() => { | |
throw new Error('No commands accepted after close'); | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment