Skip to content

Commit

Permalink
feat: change to not await onInitialized
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathannorris committed Jan 26, 2024
1 parent 251d872 commit 3bd746a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 2 additions & 4 deletions examples/openfeature-nodejs/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ const DEVCYCLE_SERVER_SDK_KEY =
let openFeatureClient: Client

async function startDevCycle() {
OpenFeature.setProvider(
await initializeDevCycle(
DEVCYCLE_SERVER_SDK_KEY,
).getOpenFeatureProvider(),
await OpenFeature.setProviderAndWait(
initializeDevCycle(DEVCYCLE_SERVER_SDK_KEY).getOpenFeatureProvider(),
)
openFeatureClient = OpenFeature.getClient()

Expand Down
10 changes: 7 additions & 3 deletions sdk/nodejs/__tests__/initialize.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DevCycleCloudClient, initializeDevCycle } from '../src/index'
import { OpenFeature } from '@openfeature/server-sdk'

jest.mock('../src/bucketing')
jest.mock('@devcycle/config-manager')
Expand All @@ -16,11 +17,14 @@ describe('NodeJS SDK Initialize', () => {
})

it('successfully creates a OpenFeature provider', async () => {
const provider = await initializeDevCycle(
'dvc_server_token',
).getOpenFeatureProvider()
const provider =
initializeDevCycle('dvc_server_token').getOpenFeatureProvider()
expect(provider).toBeDefined()
expect(provider.status).toBe('NOT READY')
await OpenFeature.setProviderAndWait(provider)
expect(provider.status).toBe('READY')
const client = OpenFeature.getClient()
expect(client).toBeDefined()
})

it('fails to initialize in Local Bucketing mode when no token is provided', () => {
Expand Down
3 changes: 1 addition & 2 deletions sdk/nodejs/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,9 @@ export class DevCycleClient {
})
}

async getOpenFeatureProvider(): Promise<DevCycleProvider> {
getOpenFeatureProvider(): DevCycleProvider {
if (this.openFeatureProvider) return this.openFeatureProvider

await this.onInitialized
this.openFeatureProvider = new DevCycleProvider(this)
return this.openFeatureProvider
}
Expand Down

0 comments on commit 3bd746a

Please sign in to comment.