UNPKG

@loopback/docs

Version:

Documentation files rendered at [https://loopback.io](https://loopback.io)

52 lines (34 loc) 1.6 kB
--- lang: en title: 'API docs: context.binding.getvalue' keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI sidebar: lb4_sidebar editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/context permalink: /doc/en/lb4/apidocs.context.binding.getvalue.html --- <!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [@loopback/context](./context.md) &gt; [Binding](./context.binding.md) &gt; [getValue](./context.binding.getvalue.md) ## Binding.getValue() method This is an internal function optimized for performance. Users should use `@inject(key)` or `ctx.get(key)` instead. Get the value bound to this key. Depending on `isSync`<!-- -->, this function returns either: - the bound value - a promise of the bound value Consumers wishing to consume sync values directly should use `isPromiseLike` to check the type of the returned value to decide how to handle it. <b>Signature:</b> ```typescript getValue(ctx: Context, session?: ResolutionSession): ValueOrPromise<T>; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | | ctx | [Context](./context.context.md) | Context for the resolution | | session | [ResolutionSession](./context.resolutionsession.md) | Optional session for binding and dependency resolution | <b>Returns:</b> [ValueOrPromise](./context.valueorpromise.md)<!-- -->&lt;T&gt; ## Example ``` const result = binding.getValue(ctx); if (isPromiseLike(result)) { result.then(doSomething) } else { doSomething(result); } ```