Skip to content

Latest commit

 

History

History
440 lines (236 loc) · 9.59 KB

File metadata and controls

440 lines (236 loc) · 9.59 KB

quickjs-emscriptenquickjs-emscripten-coreReadme | Exports


quickjs-emscripten / quickjs-emscripten-core / Lifetime

Class: Lifetime<T, TCopy, Owner>

A lifetime prevents access to a value after the lifetime has been disposeed.

Typically, quickjs-emscripten uses Lifetimes to protect C memory pointers.

Contents

Extends

Type parameters

T

TCopy = never

Owner = never

Implements

Constructors

new Lifetime(_value, copier, disposer, _owner)

new Lifetime<T, TCopy, Owner>(_value, copier?, disposer?, _owner?): Lifetime<T, TCopy, Owner>

When the Lifetime is disposed, it will call disposer(_value). Use the disposer function to implement whatever cleanup needs to happen at the end of value's lifetime.

_owner is not used or controlled by the lifetime. It's just metadata for the creator.

Parameters

_value: T

copier?: (value) => TCopy

disposer?: (value) => void

_owner?: Owner

Returns

Lifetime<T, TCopy, Owner>

Overrides

quickjs-emscripten-core.UsingDisposable.constructor

Source

packages/quickjs-emscripten-core/src/lifetime.ts:83

Properties

_alive

protected _alive: boolean = true

Source

packages/quickjs-emscripten-core/src/lifetime.ts:72


_constructorStack

protected _constructorStack: undefined | string

Source

packages/quickjs-emscripten-core/src/lifetime.ts:73


_owner?

protected readonly _owner?: Owner

Source

packages/quickjs-emscripten-core/src/lifetime.ts:87


_value

protected readonly _value: T

Source

packages/quickjs-emscripten-core/src/lifetime.ts:84


copier?

protected readonly copier?: (value) => TCopy

Parameters

value: T | TCopy

Returns

TCopy

Source

packages/quickjs-emscripten-core/src/lifetime.ts:85


disposer?

protected readonly disposer?: (value) => void

Parameters

value: T | TCopy

Returns

void

Source

packages/quickjs-emscripten-core/src/lifetime.ts:86

Accessors

alive

get alive(): boolean

Returns

boolean

true if the object is alive

false after the object has been disposed

Source

packages/quickjs-emscripten-core/src/lifetime.ts:92


dupable

get dupable(): boolean

Returns

boolean

Source

packages/quickjs-emscripten-core/src/lifetime.ts:111


owner

get owner(): undefined | Owner

Returns

undefined | Owner

Source

packages/quickjs-emscripten-core/src/lifetime.ts:107


value

get value(): T

The value this Lifetime protects. You must never retain the value - it may become invalid, leading to memory errors.

Throws

If the lifetime has been disposed already.

Returns

T

Source

packages/quickjs-emscripten-core/src/lifetime.ts:102

Methods

[dispose]()

[dispose](): void

Just calls the standard .dispose() method of this class.

Returns

void

Implementation of

quickjs-emscripten-core.Disposable.[dispose]

Inherited from

quickjs-emscripten-core.UsingDisposable.[dispose]

Source

packages/quickjs-emscripten-core/src/lifetime.ts:47


consume()

consume(map)

consume<O>(map): O

Call map with this lifetime, then dispose the lifetime.

Type parameters

O

Parameters

map: (lifetime) => O

Returns

O

the result of map(this).

Source

packages/quickjs-emscripten-core/src/lifetime.ts:135

consume(map)

consume<O>(map): O

Type parameters

O

Parameters

map: (lifetime) => O

Returns

O

Source

packages/quickjs-emscripten-core/src/lifetime.ts:138


dispose()

dispose(): void

Dispose of value and perform cleanup.

Returns

void

Implementation of

quickjs-emscripten-core.Disposable.dispose

Overrides

quickjs-emscripten-core.UsingDisposable.dispose

Source

packages/quickjs-emscripten-core/src/lifetime.ts:174


dup()

dup(): Lifetime<TCopy, TCopy, Owner>

Create a new handle pointing to the same value.

Returns

Lifetime<TCopy, TCopy, Owner>

Source

packages/quickjs-emscripten-core/src/lifetime.ts:118


map()

map(map)

map<O>(map): O

Call map with this lifetime, returning the result. Does not dispose the lifetime.

Type parameters

O

Parameters

map: (lifetime) => O

Returns

O

the result of map(this).

Source

packages/quickjs-emscripten-core/src/lifetime.ts:151

map(map)

map<O>(map): O

Type parameters

O

Parameters

map: (lifetime) => O

Returns

O

Source

packages/quickjs-emscripten-core/src/lifetime.ts:152


tap()

tap(fn)

tap(fn): Lifetime<T, TCopy, Owner>

Call fn with this lifetime, then return this. Does not dispose the lifetime. Useful for imperative operations within an expression, like when you're building up objects, or to add logging in the middle of a call chain.

Parameters

fn: (lifetime) => void

Returns

Lifetime<T, TCopy, Owner>

this

Source

packages/quickjs-emscripten-core/src/lifetime.ts:164

tap(fn)

tap(fn): QuickJSHandle

Parameters

fn: (lifetime) => void

Returns

QuickJSHandle

Source

packages/quickjs-emscripten-core/src/lifetime.ts:165


Generated using typedoc-plugin-markdown and TypeDoc