-
Notifications
You must be signed in to change notification settings - Fork 63
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
Showing
8 changed files
with
165 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
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
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,52 @@ | ||
class Vault { | ||
constructor (id, bridge, timers) { | ||
this._bridge = bridge; | ||
this._timers = timers; | ||
this._event = `execution.vault.${id}`; | ||
|
||
this._handler = (eventId, ...args) => { | ||
this._timers.clearEvent(eventId, ...args); | ||
}; | ||
|
||
this._bridge.on(this._event, this._handler); | ||
} | ||
|
||
exec (...args) { | ||
return new Promise((resolve, reject) => { | ||
const eventId = this._timers.setEvent((err, ...args) => { | ||
if (err) { | ||
return reject(err instanceof Error ? err : new Error(err.message || err)); | ||
} | ||
|
||
resolve(...args); | ||
}); | ||
|
||
this._bridge.dispatch(this._event, eventId, ...args); | ||
}); | ||
} | ||
|
||
dispose () { | ||
this._bridge.off(this._event, this._handler); | ||
} | ||
} | ||
|
||
const getVaultInterface = (vault) => { | ||
return { | ||
get: (key) => { | ||
return vault('get', key); | ||
}, | ||
|
||
set: (key, value) => { | ||
return vault('set', key, value); | ||
}, | ||
|
||
unset: (key) => { | ||
return vault('unset', key); | ||
} | ||
}; | ||
}; | ||
|
||
module.exports = { | ||
Vault, | ||
getVaultInterface | ||
}; |
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
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