Skip to content

Starting & Stopping

createService returns a ServiceApi immediately — the connection is established in the background. open() is how you wait for it:

const service = createService('1.0.0', handler)
await service.open() // resolves once connected

You rarely need it when the service is the whole program. You do need it before the first act(), and before any boot loop that re-attaches deferred keys.

Service(...) configures the service and then consumes on the calling thread, so it never returns while the service is up:

from requence.service import Service
Service("1.0.0", lambda ctx: ctx.input) # blocks here forever

That is the right shape when the service is the whole program. But it means there is no instance to call methods on — so act() and close(), which are both methods, are out of reach.

Use Service.start(...) when you need either. It is the same configuration with the consume loop on a thread of its own, and it returns the instance once connected:

import threading
from requence.service import Service
service = Service.start("1.0.0", lambda ctx: ctx.input)
# ...connected; `service` is usable here
threading.Event().wait() # keep the main thread alive; see below
Service(...) Service.start(...)
Returns never (while up) once connected
act() / close() unreachable usable
Bad credentials raises raises
Consume thread the caller’s a daemon thread

start(..., timeout=30.0) bounds only the first connect; every drop after it reconnects in the background as always. A first connect that never lands raises TimeoutError and stops retrying, so you never get back an instance you cannot use.

const service = createService('1.0.0', handler)
// Later — gracefully disconnect
await service.close()