# createScope

```ts
function createScope(parent?: Scope): [Scope, () => Future<void>]
```

Create a new [Scope](https://frontside.com/effection/api/v3/Scope.md) as a child of `parent`, inheriting all its contexts.
along with a method to destroy the scope. Whenever the scope is destroyd, all
tasks and resources it contains will be halted.

This function is used mostly by frameworks as an intergration point to enter
Effection.

### Examples
#### Example 1
```js
import { createScope, sleep, suspend } from "effection";

let [scope, destroy] = createScope();

let delay = scope.run(function*() {
  yield* sleep(1000);
});
scope.run(function*() {
  try {
    yield* suspend();
   } finally {
     console.log('done!');
   }
});
await delay;
await destroy(); // prints "done!";
```

---
### Parameters


**parent**<span class="inline-block bg-sky-100 rounded px-2 text-sm text-sky-900 mx-1">optional</span>: [Scope](https://frontside.com/effection/api/v3/Scope.md)


scope. If no parent is specified it will be free standing.
### Return Type


&lbrack;[Scope](https://frontside.com/effection/api/v3/Scope.md), () => [Future](https://frontside.com/effection/api/v3/Future.md)&lt;void&gt;&rbrack;


a tuple containing the freshly created scope, along with a function to
destroy it.

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

```ts
function createScope(parent: Frame): [Scope, () => Future<void>]
```

### Parameters


**parent**: Frame
### Return Type


&lbrack;[Scope](https://frontside.com/effection/api/v3/Scope.md), () => [Future](https://frontside.com/effection/api/v3/Future.md)&lt;void&gt;&rbrack;

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

```ts
function createScope(parent?: Frame | Scope): [Scope, () => Future<void>]
```

### Parameters


**parent**<span class="inline-block bg-sky-100 rounded px-2 text-sm text-sky-900 mx-1">optional</span>: Frame | [Scope](https://frontside.com/effection/api/v3/Scope.md)
### Return Type


&lbrack;[Scope](https://frontside.com/effection/api/v3/Scope.md), () => [Future](https://frontside.com/effection/api/v3/Future.md)&lt;void&gt;&rbrack;

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