# Scope

```ts
interface Scope
```

A programatic API to interact with an Effection scope from outside of an
[Operation](https://frontside.com/effection/api/v3/Operation.md).

Most often this is used to integrate external APIs with Effection by
capturing a `Scope` from a running operation with [useScope](https://frontside.com/effection/api/v3/useScope.md), and then
using it to call back into itself from a callback.

The following example calls into Effection to implement a proxy around a
google search by using [express.js](https://expressjs.com).

### Examples
#### Example 1
```javascript
import { main, useScope, suspend } from "effection";
import { express } from "express";

await main(function*() {
  let scope = yield* useScope();
  express().get("/", (req, resp) => {
    return scope.run(function*() {
      let signal = yield* useAbortSignal();
      let response = yield* fetch(`https://google.com?q=${req.params.q}`, { signal });
      resp.send(yield* response.text());
    });
  });
  yield* suspend();
});
```
---


### Methods
<dl>
<dt class="border-dotted [&:not(:first-child)]:border-t-2 [&:not(:first-child)]:pt-3 [&:not(:first-child)]:mt-2"><h4 id="run" class="inline scroll-mt-[100px]">run</h4>&lt;T&gt;(**operation**: () => [Operation](https://frontside.com/effection/api/v3/Operation.md)&lt;T&gt;): [Task](https://frontside.com/effection/api/v3/Task.md)&lt;T&gt;</dt>
<dd class="flex flex-col [&>pre]:mb-3 [&>p:not(:first-child)]:mt-0" >
Spawn an [Operation](https://frontside.com/effection/api/v3/Operation.md) within `Scope`.

This is used to create concurrent tasks from _outside_ of a running
operation.

</dd>
<dt class="border-dotted [&:not(:first-child)]:border-t-2 [&:not(:first-child)]:pt-3 [&:not(:first-child)]:mt-2"><h4 id="spawn" class="inline scroll-mt-[100px]">spawn</h4>&lt;T&gt;(**operation**: () => [Operation](https://frontside.com/effection/api/v3/Operation.md)&lt;T&gt;): [Operation](https://frontside.com/effection/api/v3/Operation.md)&lt;[Task](https://frontside.com/effection/api/v3/Task.md)&lt;T&gt;&gt;</dt>
<dd class="flex flex-col [&>pre]:mb-3 [&>p:not(:first-child)]:mt-0" >
Spawn an [Operation](https://frontside.com/effection/api/v3/Operation.md) within `Scope`.

This is used to create concurrent tasks from _within_ a running
operation. To create concurrent from outside of Effection, use
[Scope#run](https://frontside.com/effection/api/v3/Scope.md)
</dd>
<dt class="border-dotted [&:not(:first-child)]:border-t-2 [&:not(:first-child)]:pt-3 [&:not(:first-child)]:mt-2"><h4 id="get" class="inline scroll-mt-[100px]">get</h4>&lt;T&gt;(**context**: [Context](https://frontside.com/effection/api/v3/Context.md)&lt;T&gt;): T | undefined</dt>
<dd class="flex flex-col [&>pre]:mb-3 [&>p:not(:first-child)]:mt-0" >
Get a [Context](https://frontside.com/effection/api/v3/Context.md) value from outside of an operation.
</dd>
<dt class="border-dotted [&:not(:first-child)]:border-t-2 [&:not(:first-child)]:pt-3 [&:not(:first-child)]:mt-2"><h4 id="set" class="inline scroll-mt-[100px]">set</h4>&lt;T&gt;(**context**: [Context](https://frontside.com/effection/api/v3/Context.md)&lt;T&gt;, **value**: T): T</dt>
<dd class="flex flex-col [&>pre]:mb-3 [&>p:not(:first-child)]:mt-0" >
Set the value of a [Context](https://frontside.com/effection/api/v3/Context.md) from outside of an operation
</dd>
<dt class="border-dotted [&:not(:first-child)]:border-t-2 [&:not(:first-child)]:pt-3 [&:not(:first-child)]:mt-2"><h4 id="expect" class="inline scroll-mt-[100px]">expect</h4>&lt;T&gt;(**context**: [Context](https://frontside.com/effection/api/v3/Context.md)&lt;T&gt;): T</dt>
<dd class="flex flex-col [&>pre]:mb-3 [&>p:not(:first-child)]:mt-0" >
Get a [Context](https://frontside.com/effection/api/v3/Context.md) value from outside of an operation, and throw
a `MissingContextError` if this context is not specified for this scope.

</dd>
<dt class="border-dotted [&:not(:first-child)]:border-t-2 [&:not(:first-child)]:pt-3 [&:not(:first-child)]:mt-2"><h4 id="delete" class="inline scroll-mt-[100px]">delete</h4>&lt;T&gt;(**context**: [Context](https://frontside.com/effection/api/v3/Context.md)&lt;T&gt;): boolean</dt>
<dd class="flex flex-col [&>pre]:mb-3 [&>p:not(:first-child)]:mt-0" >
Remove a [Context](https://frontside.com/effection/api/v3/Context.md) value from this scope.

</dd>
<dt class="border-dotted [&:not(:first-child)]:border-t-2 [&:not(:first-child)]:pt-3 [&:not(:first-child)]:mt-2"><h4 id="hasOwn" class="inline scroll-mt-[100px]">hasOwn</h4>&lt;T&gt;(**context**: [Context](https://frontside.com/effection/api/v3/Context.md)&lt;T&gt;): boolean</dt>
<dd class="flex flex-col [&>pre]:mb-3 [&>p:not(:first-child)]:mt-0" >
Check if scope has its own unique value for `context`.

</dd>
</dl>

[View code](https://github.com/thefrontside/effection/tree/effection-v3.6.1/lib/types.ts#L186)
