# createScope

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

Create a new [Scope](https://frontside.com/effection/api/v4/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!";
```

`createScope()` also supports explicit resource management
---
#### Example 2
```js
{
 await using scope = createScope();

 let delay = scope.run(function*() {
   yield* sleep(1000);
 });

 scope.run(function*() {
   try {
     yield* suspend();
   } finally {
     console.log('done!');
   }
 });

 await delay;
 // prints "done!";
}
```

---
### Parameters





scope. If no parent is specified it will derive directly from [global](https://frontside.com/effection/api/v4/global.md)
### Return Type


[Scope](https://frontside.com/effection/api/v4/Scope.md) &amp; AsyncDisposable &amp; &lbrack;[Scope](https://frontside.com/effection/api/v4/Scope.md), () => [Future](https://frontside.com/effection/api/v4/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-v4.2.0/lib/scope.ts#L67)
