-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Beau Shinkle
committed
Feb 3, 2023
1 parent
5643d50
commit 0dd9240
Showing
3 changed files
with
71 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"0x5c9074a80de4f1b810a36e8a2a54c3e36184bc700483daf185e5cd367d2e8ee0": true, | ||
"0xad8ca58d1639fcc8423ae75dd8aa69cdf1e916661a6ce9e01aebe1500f44c3d1": true, | ||
"0x1f0d3098d4e9f13771d972bdf4c5efc8273acf22a848846cf5e666cbed3ae3a5": true | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const EventEmitter = require('events') | ||
|
||
let brainLock = false | ||
const emitter = new EventEmitter() | ||
const fs = require('fs') | ||
|
||
module.exports = { | ||
async read(key) { | ||
if (brainLock) { | ||
await new Promise(resolve => emitter.once('unlocked', resolve)) | ||
} | ||
brainLock = true | ||
|
||
const data = await fs.promises.readFile("brain.json") | ||
const value = JSON.parse(data.toString())[key] | ||
|
||
brainLock = false | ||
emitter.emit('unlocked') | ||
return value | ||
}, | ||
async write(key, val) { | ||
if (brainLock) { | ||
await new Promise(resolve => emitter.once('unlocked', resolve)) | ||
} | ||
brainLock = true | ||
|
||
const data = await fs.promises.readFile("brain.json") | ||
let brain = JSON.parse(data.toString()) | ||
brain[key] = val | ||
await fs.promises.writeFile("brain.json", JSON.stringify(brain, null, 2)) | ||
|
||
brainLock = false | ||
emitter.emit('unlocked') | ||
} | ||
} |