@libp2p/interfaces
TypeScript icon, indicating that this package has built-in type declarations

3.3.2 • Public • Published

@libp2p/interfaces

libp2p.io Discuss codecov CI

Common code shared by the various libp2p interfaces

Table of contents

Install

$ npm i @libp2p/interfaces

Usage

AbortError

Throw an error with a .code property of 'ABORT_ERR':

import { AbortError } from '@libp2p/interfaces/errors'

throw new AbortError()

Events

Typed events:

import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events'

export interface MyEmitterEvents {
  'some-event': CustomEvent<number>;
}

class MyEmitter extends EventEmitter<MyEmitterEvents> {

}

// later
const myEmitter = new MyEmitter()
myEmitter.addEventListener('some-event', (evt) => {
  const num = evt.detail // <-- inferred as number
})

AbortOptions

import type { AbortOptions } from '@libp2p/interfaces'

Startable

Lifecycles for components

import { start, stop, isStartable } from '@libp2p/interfaces/startable'
import type { Startable } from '@libp2p/interfaces/startable'

class MyStartable implements Startable {
  // .. implementation methods
}

const myStartable = new MyStartable()

isStartable(myStartable) // returns true

await start(myStartable)
await stop(myStartable)

API Docs

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Readme

Keywords

Package Sidebar

Install

npm i @libp2p/interfaces

Weekly Downloads

13,677

Version

3.3.2

License

Apache-2.0 OR MIT

Unpacked Size

31.4 kB

Total Files

25

Last publish

Collaborators

  • jacobheun
  • npm-service-account-libp2p
  • alanshaw
  • vascosantos
  • achingbrain
  • daviddias