license import { ModuleRpcServer } from '../../server' ; import { NumberService } from './service' ; export type NumberHandler = ModuleRpcServer . ServiceHandlerFor < NumberService > ; /**
 * Return a handler where the methods of the BankingService are actually implemented.
 *
 * We wrap it in a function to allow for closures, so that you can have variables scoped
 * to the lifetime of the server (such as the mock store `users` in this instance).
 */ export const getNumberHandler = ( ) : NumberHandler => { return { async increment ( { value } ) { return { value : value + 1 } ; } , /** Server-side streams are offered with a slightly different signature */ async streamNumbers ( { max , sleepMs } , { onReady , onMessage } ) { let closed = false ; onReady ( ( ) => { closed = true ; } ) ; for ( let counter = 0 ; counter < max ; ++ counter ) { if ( closed ) { break ; } onMessage ( { counter } ) ; await sleep ( sleepMs ) ; } } , } ; } ; /**
 * Like setTimeout but with promises
 */ async function sleep ( timeInMillis ) { return new Promise < void > ( y => setTimeout ( y , timeInMillis ) ) ; }