MCPcopy Index your code
hub / github.com/loopbackio/loopback-next / greetWithSyncUser

Function greetWithSyncUser

examples/context/src/sync-async.ts:31–47  ·  view source on GitHub ↗
(ctx: Context)

Source from the content-addressed store, hash-verified

29const GREETER = BindingKey.create<Greeter>('greeter');
30
31async function greetWithSyncUser(ctx: Context) {
32 // Set the current user to `John` (a constant value)
33 // As a result, CURRENT_USER can be resolved synchronously
34 ctx.bind(CURRENT_USER).to('John (sync)');
35
36 // Greeter has a dependency on current user which can be resolved
37 // synchronously. This allows GREETER to be resolved either synchronously or
38 // asynchronously.
39 // Get an instance of Greeter synchronously
40 let greeter = ctx.getSync(GREETER);
41 console.log('%s', greeter.hello());
42
43 // Get an instance of Greeter asynchronously
44 greeter = await ctx.get(GREETER);
45 console.log('%s', greeter.hello());
46 return greeter;
47}
48
49async function greetWithAsyncUser(ctx: Context) {
50 // Now set the current user to an async factory

Callers 1

mainFunction · 0.85

Calls 6

toMethod · 0.80
getSyncMethod · 0.80
logMethod · 0.65
helloMethod · 0.65
getMethod · 0.65
bindMethod · 0.45

Tested by

no test coverage detected