Skip to main content

Creating Semaphore adapters

Implementing your custom ISemaphoreAdapter

In order to create an adapter you need to implement the ISemaphoreAdapter contract.

Testing your custom ISemaphoreAdapter

We provide a complete test suite to test your semaphore adapter implementation. Simply use the semaphoreAdapterTestSuite function:

  • Preconfigured Vitest test cases
  • Common edge case coverage

Usage example:

// filename: MySemaphoreAdapter.test.ts

import { beforeEach, describe, expect, test } from "vitest";
import { semaphoreAdapterTestSuite } from "eridu-tech/semaphore/test-utilities";
import { MemorySemaphoreAdapter } from "./MemorySemaphoreAdapter.js";

describe("class: MySemaphoreAdapter", () => {
semaphoreAdapterTestSuite({
createAdapter: () => new MemorySemaphoreAdapter(),
test,
beforeEach,
expect,
describe,
});
});

Implementing your custom ISemaphoreFactory class

In some cases, you may need to implement a custom SemaphoreFactory class to optimize performance for your specific technology stack. You can then directly implement the ISemaphoreFactory contract.

Testing your custom ISemaphoreFactory class

We provide a complete test suite to verify your custom event-bus class implementation. Simply use the semaphoreFactoryTestSuite function:

  • Preconfigured Vitest test cases
  • Standardized event-bus behavior validation
  • Common edge case coverage

Usage example:

// filename: MySemaphoreFactory.test.ts

import { beforeEach, describe, expect, test } from "vitest";
import { semaphoreFactoryTestSuite } from "eridu-tech/semaphore/test-utilities";
import { MySemaphoreFactory } from "./MySemaphoreFactory.js";

describe("class: MySemaphoreFactory", () => {
semaphoreFactoryTestSuite({
createSemaphoreFactory: () => new MySemaphoreFactory(),
test,
beforeEach,
expect,
describe,
});
});

Further information

For further information refer to eridu-tech/semaphore API docs.