-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
11 changed files
with
58 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "@zerva/bin", | ||
"type": "module", | ||
"version": "0.55.3", | ||
"version": "0.55.5", | ||
"description": "🌱 Zerva Command Line Tool", | ||
"author": { | ||
"email": "[email protected]", | ||
|
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
// (C)opyright 2021-07-15 Dirk Holtwick, holtwick.it. All rights reserved. | ||
|
||
export * from './_types' | ||
export * from './server' | ||
export * from './client' |
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,8 @@ | ||
import { useSingletonFlag } from './singleton' | ||
|
||
describe('singleton.spec', () => { | ||
it('should only once', async () => { | ||
const dispose = useSingletonFlag('test') | ||
dispose() | ||
}) | ||
}) |
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,25 @@ | ||
import type { LoggerInterface } from 'zeed' | ||
|
||
/** Make sure the flag is only in use once globally. */ | ||
export function useSingletonFlag(name: string, log?: LoggerInterface) { | ||
const _global = globalThis as any | ||
if (_global._zerva_singleton_flags == null) | ||
_global._zerva_singleton_flags = {} | ||
|
||
if (_global._zerva_singleton_flags[name] === true) { | ||
const msg = `Singleton named '${name}' called twice!` | ||
log?.error(msg) | ||
throw new Error(msg) | ||
} | ||
|
||
_global._zerva_singleton_flags[name] = true | ||
|
||
return () => { | ||
if (_global._zerva_singleton_flags[name] !== true) { | ||
const msg = `Singleton named '${name}' has been disposed more than once!` | ||
log?.error(msg) | ||
throw new Error(msg) | ||
} | ||
_global._zerva_singleton_flags[name] = false | ||
} | ||
} |