diff --git a/packages/svrx/__tests__/spec/svrx.io.js b/packages/svrx/__tests__/spec/svrx.io.js index bd316751..492eab62 100644 --- a/packages/svrx/__tests__/spec/svrx.io.js +++ b/packages/svrx/__tests__/spec/svrx.io.js @@ -41,14 +41,14 @@ describe('IO', () => { }); it('io.call', async () => { - io.registService('hello', async (payload) => `hi ${payload}`); + io.register('hello', async (payload) => `hi ${payload}`); expect(await io.call('hello', 'leeluolee')).to.equal('hi leeluolee'); }); it('io.call limit error', async () => { expect(() => { for (let i = 0; i < 1000; i += 1) { - io.registService(`hello${i}`, async (payload) => `hi ${i} ${payload}`); + io.register(`hello${i}`, async (payload) => `hi ${i} ${payload}`); } }).to.throwError(/max service size limit exceeded/); }); @@ -57,7 +57,7 @@ describe('IO', () => { const svrx = createServer({ root: __dirname, }); - svrx.io.registService('hello', async (payload) => `hi ${payload}`); + svrx.io.register('hello', async (payload) => `hi ${payload}`); await svrx.setup(); return supertest(svrx.callback()) .post(IO_PATH) @@ -70,7 +70,7 @@ describe('IO', () => { const svrx = createServer({ root: __dirname, }); - svrx.io.registService('error', async (payload) => { + svrx.io.register('error', async (payload) => { throw Error(`hi ${payload}`); }); await svrx.setup(); diff --git a/packages/svrx/lib/io/index.js b/packages/svrx/lib/io/index.js index 4d5c62cf..db5036d9 100644 --- a/packages/svrx/lib/io/index.js +++ b/packages/svrx/lib/io/index.js @@ -46,10 +46,15 @@ class IO { }); } + // @deprecated registService(name, handler) { this[SERVICE_CACHE].set(name, handler); } + register(name, handler) { + this[SERVICE_CACHE].set(name, handler); + } + async call(name, payload) { const handler = this[SERVICE_CACHE].get(name); if (typeof handler !== 'function') {