-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
1 parent
f57a2d7
commit bb08c70
Showing
21 changed files
with
1,362 additions
and
1,137 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 @@ | ||
{ | ||
"files.associations": { | ||
"api-extractor.json": "jsonc" | ||
} | ||
} |
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,47 +1,47 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
namespace emnapi { | ||
export interface IDeferrdValue<T = any> { | ||
resolve: (value: T) => void | ||
reject: (reason?: any) => void | ||
import { IStoreValue, Store } from './Store' | ||
import { envStore } from './util' | ||
|
||
export interface IDeferrdValue<T = any> { | ||
resolve: (value: T) => void | ||
reject: (reason?: any) => void | ||
} | ||
|
||
export class Deferred<T = any> implements IStoreValue { | ||
public static create<T = any> (env: napi_env, value: IDeferrdValue<T>): Deferred { | ||
const deferred = new Deferred<T>(env, value) | ||
envStore.get(env)!.deferredStore.add(deferred) | ||
return deferred | ||
} | ||
|
||
public id: number | ||
public env: napi_env | ||
public value: IDeferrdValue<T> | ||
|
||
public constructor (env: napi_env, value: IDeferrdValue<T>) { | ||
this.id = 0 | ||
this.env = env | ||
this.value = value | ||
} | ||
|
||
export class Deferred<T = any> implements IStoreValue { | ||
public static create<T = any> (env: napi_env, value: IDeferrdValue<T>): Deferred { | ||
const deferred = new Deferred<T>(env, value) | ||
envStore.get(env)!.deferredStore.add(deferred) | ||
return deferred | ||
} | ||
|
||
public id: number | ||
public env: napi_env | ||
public value: IDeferrdValue<T> | ||
|
||
public constructor (env: napi_env, value: IDeferrdValue<T>) { | ||
this.id = 0 | ||
this.env = env | ||
this.value = value | ||
} | ||
|
||
public resolve (value: T): void { | ||
this.value.resolve(value) | ||
this.dispose() | ||
} | ||
|
||
public reject (reason?: any): void { | ||
this.value.reject(reason) | ||
this.dispose() | ||
} | ||
|
||
public dispose (): void { | ||
envStore.get(this.env)!.deferredStore.remove(this.id) | ||
this.id = 0 | ||
this.value = null! | ||
} | ||
public resolve (value: T): void { | ||
this.value.resolve(value) | ||
this.dispose() | ||
} | ||
|
||
export class DeferredStore extends Store<Deferred> { | ||
public constructor () { | ||
super() | ||
} | ||
public reject (reason?: any): void { | ||
this.value.reject(reason) | ||
this.dispose() | ||
} | ||
|
||
public dispose (): void { | ||
envStore.get(this.env)!.deferredStore.remove(this.id) | ||
this.id = 0 | ||
this.value = null! | ||
} | ||
} | ||
|
||
export class DeferredStore extends Store<Deferred> { | ||
public constructor () { | ||
super() | ||
} | ||
} |
Oops, something went wrong.