-
Notifications
You must be signed in to change notification settings - Fork 1
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
Daniel Schaffer
committed
Mar 15, 2019
1 parent
6f3c7de
commit 4de738b
Showing
35 changed files
with
801 additions
and
108 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,52 +1,7 @@ | ||
# @dandi/common | ||
|
||
`@dandi/common` provides common types and utilities for the rest of the | ||
`@dandi` system. | ||
**Dandi** system. | ||
|
||
`@dandi/common` does not have any dependencies on NodeJS, and therefore | ||
can be used on classes shared with projects targeted for the web. | ||
|
||
## Disposable | ||
|
||
The `Disposable` interface allows implementing classes to define | ||
behavior for cleaning up resources like IO streams, database | ||
connections, as well as Observable and other event subscriptions. | ||
|
||
When used with `@dandi/core`, `Disposable` instances are | ||
automatically disposed by Dandi at the end of their lifecycle. | ||
|
||
```typescript | ||
class MyService implements Disposable { | ||
|
||
constructor(private dbClient: DbClient) {} | ||
|
||
public dispose(reason: string): void { | ||
this.dbClient.release(); | ||
} | ||
|
||
} | ||
``` | ||
|
||
### Disposable Utilities | ||
|
||
`Disposable` is also a static class provides several utility functions: | ||
|
||
* **isDisposable(obj)** - Returns `true` if the object implements | ||
`dispose()`; otherwise, `false`. | ||
|
||
* **makeDisposable(obj, disposeFn)** - Modifies the specified object to | ||
add the provided {@see DisposeFn} as the `Disposable.dispose` | ||
implementation. If the object already has a function member named | ||
`dispose`, it is wrapped and called before the new function. | ||
|
||
* **use(obj, fn)** - Invokes the specified function in a `try`/`catch`, | ||
statement, then `finally` disposes the object. Returns the value | ||
returned by `fn`, or rethrows the error thrown by it. | ||
|
||
* **useAsync(obj, fn)** - Same as `use`, but `fn` is invoked using `await`. | ||
|
||
* **remapDisposed(target, reason)** - Overwrites members of the target | ||
such that functions and property/field accessors throw an | ||
`AlreadyDisposedError`, a read-only `disposed` property is set with | ||
the value `true`, and the target is frozen (using `Object.freeze`) to | ||
prevent further modification. |
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
3 changes: 3 additions & 0 deletions
3
packages/dandi/common/src/async-mutex-lock-already-released-error.ts
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
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 +1,6 @@ | ||
/** | ||
* A `symbol` or `string` presenting the custom inspector for the current environment. | ||
* | ||
* The value will be the `util.inspect.custom` symbol for NodeJS, or `toString()` for browser environments. | ||
*/ | ||
export const CUSTOM_INSPECTOR: string | symbol |
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,3 +1,6 @@ | ||
import { globalSymbol } from './global.symbol' | ||
|
||
/** | ||
* @ignore | ||
*/ | ||
export const DISABLE_REMAP = globalSymbol('Disposable.DISABLE_REMAP') |
Oops, something went wrong.