-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(actors): expose
ActorContext
to actor RPCs & init
- Loading branch information
1 parent
6b0c50b
commit 5d52aa3
Showing
15 changed files
with
271 additions
and
58 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
title: Actor | ||
--- | ||
|
||
<Note> | ||
Documentation coming very soon! | ||
</Note> | ||
|
||
## Performance Tips | ||
|
||
### Do as little work on the actor as possible | ||
|
||
Opt to run as many database queries and other expensive operations on the request before sending a message to the actor. | ||
|
||
Scripts scale horizontally while actors can be a performance bottleneck if misused. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,34 @@ | ||
import { ModuleContextParams } from "../context.ts"; | ||
import { Config } from "../mod.ts"; | ||
import { ActorContext } from "../mod.ts"; | ||
import { ScheduleDriver, StorageDriver } from "./driver.ts"; | ||
|
||
/** | ||
* Actor implementation that user-made actors will extend. | ||
*/ | ||
export abstract class ActorBase< | ||
Params extends ModuleContextParams, | ||
Input, | ||
State, | ||
> { | ||
public state!: State; | ||
|
||
public constructor( | ||
public readonly config: Config, | ||
public readonly storage: StorageDriver, | ||
public readonly schedule: ScheduleDriver, | ||
public state: State, | ||
) {} | ||
|
||
public abstract initialize(input: Input): State | Promise<State>; | ||
public abstract initialize(ctx: ActorContext<ModuleContextParams>, input: Input): State | Promise<State>; | ||
|
||
/** | ||
* Runs a promise in the background. | ||
* | ||
* This allows the actor runtime to ensure that a promise completes while | ||
* returning from an RPC request early. | ||
*/ | ||
protected runInBackground(promise: Promise<void>) { | ||
// TODO: Pass this to the actor driver | ||
|
||
promise | ||
.then(() => console.log("Actor background promise complete")) | ||
.catch((err) => console.error("Actor background promise failed", err)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.