Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trie: refactor lock class #3109

Merged
merged 3 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/trie/src/trie.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
KeyEncoding,
Lock,
MapDB,
RLP_EMPTY_STRING,
ValueEncoding,
Expand All @@ -25,7 +26,6 @@ import {
import { verifyRangeProof } from './proof/range.js'
import { ROOT_DB_KEY } from './types.js'
import { _walkTrie } from './util/asyncWalk.js'
import { Lock } from './util/lock.js'
import { bytesToNibbles, matchingNibbleLength } from './util/nibbles.js'
import { TrieReadStream as ReadStream } from './util/readStream.js'
import { WalkController } from './util/walkController.js'
Expand Down
42 changes: 0 additions & 42 deletions packages/trie/src/util/lock.ts

This file was deleted.

27 changes: 0 additions & 27 deletions packages/trie/test/util/lock.spec.ts

This file was deleted.

23 changes: 23 additions & 0 deletions packages/util/test/lock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@ import { assert, describe, it } from 'vitest'

import { Lock } from '../src/index.js'

const wait = (ms: number) => new Promise((r) => setTimeout(r, ms))

describe('Lock class', () => {
it('should lock', async () => {
let global = 0
const lock = new Lock()

const f = async () => {
await lock.acquire()
const local = global
await wait(500)
global = local + 1
lock.release()
}

void f()
void f()
await wait(1500)

assert.equal(global, 2)
})
})

describe('Lock class: acquire', () => {
it('should return true when permits are available', async () => {
const lock = new Lock()
Expand Down