]> git.codecow.com Git - libnemo.git/commitdiff
Rename queueing function.
authorChris Duncan <chris@zoso.dev>
Fri, 15 May 2026 21:58:20 +0000 (14:58 -0700)
committerChris Duncan <chris@zoso.dev>
Fri, 15 May 2026 21:58:20 +0000 (14:58 -0700)
src/lib/ledger/index.ts
src/lib/ledger/queue.ts

index 6d2c8582943da4575243d54650e57d358c47284c..25ad785bb5722cfafe1841e4ffc8f3b67076596d 100644 (file)
@@ -11,7 +11,7 @@ import { BIP44_COIN_NANO, BIP44_PURPOSE, HARDENED_OFFSET } from '../constants'
 import { bytes, dec, hex, utf8 } from '../convert'
 import { Rpc } from '../rpc'
 import { Wallet } from '../wallet'
-import { enqueue } from './queue'
+import { queue } from './queue'
 
 type LedgerStatus = 'UNSUPPORTED' | 'DISCONNECTED' | 'BUSY' | 'LOCKED' | 'CONNECTED'
 
@@ -128,7 +128,7 @@ export class Ledger {
        * @returns Response object containing command status, public key, and address
        */
        static async account (index: number = 0, show: boolean = false): Promise<LedgerAccountResponse> {
-               return enqueue(async () => {
+               return queue(async () => {
                        try {
                                if (typeof index !== 'number' || index < 0 || index >= HARDENED_OFFSET) {
                                        throw new TypeError('Invalid account index')
@@ -206,7 +206,7 @@ export class Ledger {
        * connection updates.
        */
        static async disconnect (): Promise<void> {
-               enqueue(async () => {
+               queue(async () => {
                        try {
                                this.#isPolling = false
                                const hidDevices = await navigator?.hid?.getDevices?.() ?? []
@@ -368,7 +368,7 @@ export class Ledger {
        * @returns Status of command
        */
        static async #cacheBlock (index: number = 0, block: Block): Promise<LedgerResponse> {
-               return enqueue(async () => {
+               return queue(async () => {
                        try {
                                if (typeof index !== 'number' || index < 0 || index >= HARDENED_OFFSET) {
                                        throw new TypeError('Invalid account index')
@@ -425,7 +425,7 @@ export class Ledger {
        * @returns Status of command
        */
        static async #close (): Promise<LedgerResponse> {
-               return enqueue(async () => {
+               return queue(async () => {
                        const transport = await this.#transport.create(this.#openTimeout, this.#listenTimeout)
                        const response = await transport
                                .send(0xb0, 0xa7, this.#ADPU_CODES.paramUnused, this.#ADPU_CODES.paramUnused)
@@ -486,7 +486,7 @@ export class Ledger {
        * @returns Status of command
        */
        static async #open (): Promise<LedgerResponse> {
-               return enqueue(async () => {
+               return queue(async () => {
                        const name = new TextEncoder().encode('Nano')
                        const transport = await this.#transport.create(this.#openTimeout, this.#listenTimeout)
                        const response = await transport
@@ -551,7 +551,7 @@ export class Ledger {
                if (block.signature !== undefined) {
                        throw new TypeError('Block signature already exists', { cause: block.signature })
                }
-               return enqueue(async () => {
+               return queue(async () => {
                        try {
                                if (typeof index !== 'number' || index < 0 || index >= HARDENED_OFFSET) {
                                        throw new TypeError('Invalid account index')
@@ -604,7 +604,7 @@ export class Ledger {
        * @returns {Promise} Status and signature
        */
        static async #signNonce (index: number, nonce: Uint8Array<ArrayBuffer>): Promise<LedgerSignResponse> {
-               return enqueue(async () => {
+               return queue(async () => {
                        if (typeof index !== 'number' || index < 0 || index >= HARDENED_OFFSET) {
                                throw new TypeError('Invalid account index')
                        }
@@ -645,7 +645,7 @@ export class Ledger {
        * @returns Status, process name, and version
        */
        static async #version (): Promise<LedgerVersionResponse> {
-               return enqueue(async () => {
+               return queue(async () => {
                        try {
                                const transport = await this.#transport.create(this.#openTimeout, this.#listenTimeout)
                                const response = await transport
index 30560bfa7516deb34666a2641fe1f5791f87df37..460766e8ba6953dbc6c06e7ffc716b00ff470b0a 100644 (file)
@@ -6,7 +6,7 @@ let job: Promise<void> = Promise.resolve()
 /**
  * Serially executes sync and async functions.
  */
-export function enqueue<T> (task: () => T | Promise<T>): Promise<T> {
+export function queue<T> (task: () => T | Promise<T>): Promise<T> {
        if (typeof task !== 'function') throw new TypeError('task is not a function')
        const result = job.then(() => task(), () => task())
        job = result.then(() => void 0, () => void 0)