Skip to content

@std/async/unstable-semaphore should be bind methods in the constructor #7195

Description

@SnowSquire

Describe the bug
I'm an idiot and passed .release directly into a promise chains .finally()

sema.acquire().then(() => somethingAsync()).finally(sema.release)

this means i get this error

error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '#head')
    if (this.#head) {
             ^
    at release (https://jsr.io/@std/async/1.4.0/unstable_semaphore.ts:139:14)
    at <anonymous>

however this somehow worked(?) but inconsistently. so it should be changed, by binding in the constructor this.release = this.release.bind(this), or by fixing whatever makes it inconsistently work. I have no idea why it sometimes works. Seems to have a higher chance of working when the semaphore max is higher, but it works even when the total number of acquire/release calls is more than max so idk.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions