@actor-system/ask 0.0.18 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,6 @@
1
1
  import { ActorRef } from '@actor-system/core';
2
2
  import { CreateRequest } from './ask-with-callback.js';
3
3
 
4
- interface AskSyncOptions<out Req, in Res> {
5
- to: ActorRef<Req>;
6
- request: CreateRequest<Req, Res>;
7
- }
8
4
  /**
9
5
  * If an actor's mailbox uses a synchronous processing strategy,
10
6
  * this function can be used to perform an ask operation synchronously.
@@ -16,7 +12,6 @@ interface AskSyncOptions<out Req, in Res> {
16
12
  * - The actor is dead/stopped (and no tombstone response is available).
17
13
  * - The ask operation does not receive a response immediately.
18
14
  */
19
- declare const askSync: <const Req, Res>(options: AskSyncOptions<Req, Res>) => Res;
15
+ declare const askSync: <const Req, Res>(to: ActorRef<Req>, request: CreateRequest<Req, Res>) => Res;
20
16
 
21
17
  export { askSync };
22
- export type { AskSyncOptions };
@@ -1,10 +1,6 @@
1
1
  import { ActorRef } from '@actor-system/core/internal';
2
2
  import { CreateRequest } from './ask-with-callback.internal.js';
3
3
 
4
- interface AskSyncOptions<out Req, in Res> {
5
- to: ActorRef<Req>;
6
- request: CreateRequest<Req, Res>;
7
- }
8
4
  /**
9
5
  * If an actor's mailbox uses a synchronous processing strategy,
10
6
  * this function can be used to perform an ask operation synchronously.
@@ -16,7 +12,6 @@ interface AskSyncOptions<out Req, in Res> {
16
12
  * - The actor is dead/stopped (and no tombstone response is available).
17
13
  * - The ask operation does not receive a response immediately.
18
14
  */
19
- declare const askSync: <const Req, Res>(options: AskSyncOptions<Req, Res>) => Res;
15
+ declare const askSync: <const Req, Res>(to: ActorRef<Req>, request: CreateRequest<Req, Res>) => Res;
20
16
 
21
17
  export { askSync };
22
- export type { AskSyncOptions };
package/dist/ask-sync.js CHANGED
@@ -1,7 +1,12 @@
1
- import { PriorityScheduler, LocalActorRef, SchedulerType } from '@actor-system/core';
1
+ import { isActorLookup } from '@actor-system/core';
2
+ import { sync } from '@actor-system/scheduler';
2
3
  import { _askWithCallback } from './ask-with-callback.js';
3
- import { UnsupportedSyncOperationError, ReentryError, DisconnectedError, NoSynchronousResponseError, AskTimeoutError } from './errors.js';
4
+ import { UnsupportedSyncOperationError, NoSynchronousResponseError, AskTimeoutError } from './errors.js';
4
5
 
6
+ const profile = {
7
+ lane: sync,
8
+ budget: { throughput: Infinity, deadline: Infinity },
9
+ };
5
10
  /**
6
11
  * If an actor's mailbox uses a synchronous processing strategy,
7
12
  * this function can be used to perform an ask operation synchronously.
@@ -13,13 +18,13 @@ import { UnsupportedSyncOperationError, ReentryError, DisconnectedError, NoSynch
13
18
  * - The actor is dead/stopped (and no tombstone response is available).
14
19
  * - The ask operation does not receive a response immediately.
15
20
  */
16
- const askSync = (options) => {
17
- assertsActorSupportsSync(options.to);
18
- assertsActorIsIdle(options.to);
21
+ const askSync = (to, request) => {
22
+ assertsActorSupportsSync(to);
19
23
  let msgRef = null;
20
24
  let error;
21
25
  _askWithCallback({
22
- ...options,
26
+ to,
27
+ request,
23
28
  timeout: undefined,
24
29
  callback: (response) => {
25
30
  if (response instanceof AskTimeoutError) {
@@ -29,15 +34,11 @@ const askSync = (options) => {
29
34
  msgRef = { msg: response };
30
35
  }
31
36
  },
32
- props: {
33
- mailbox: {
34
- scheduler: PriorityScheduler.create("sync"),
35
- },
36
- },
37
+ props: { profile },
37
38
  });
38
39
  if (error)
39
40
  throw error;
40
- assertsSynchronousResponse(options.to, msgRef);
41
+ assertsSynchronousResponse(to, msgRef);
41
42
  return msgRef.msg;
42
43
  };
43
44
  const assertsSynchronousResponse = (to, response) => {
@@ -46,20 +47,12 @@ const assertsSynchronousResponse = (to, response) => {
46
47
  }
47
48
  };
48
49
  const assertsActorSupportsSync = (to) => {
49
- if (!(to instanceof LocalActorRef)) {
50
+ if (!isActorLookup(to)) {
50
51
  throw new UnsupportedSyncOperationError(`Synchronous ask operations are only supported for local actors. Actor '${to.path}' is not a local actor reference.`, to);
51
52
  }
52
- if (to._mailbox.schedulerType !== SchedulerType.Sync) {
53
+ if (to._getActor().dispatcher.scheduler !== sync) {
53
54
  throw new UnsupportedSyncOperationError(`Actor '${to.path}' does not support synchronous processing. Ensure the actor's mailbox is configured with a synchronous scheduler.`, to);
54
55
  }
55
56
  };
56
- const assertsActorIsIdle = (to) => {
57
- if (to._mailbox.ongoingProcess !== undefined) {
58
- throw new ReentryError(`Synchronous ask cannot be performed because actor '${to.path}' is currently processing another message (reentrancy).`, to);
59
- }
60
- if (to._mailbox.state !== "connected") {
61
- throw new DisconnectedError(`Synchronous ask cannot be performed because actor '${to.path}' is not in a connected state.`, to);
62
- }
63
- };
64
57
 
65
58
  export { askSync };
@@ -1,5 +1,5 @@
1
1
  import { receiveMessage, stopped } from '@actor-system/behaviors';
2
- import { $system, signal } from '@actor-system/core';
2
+ import { isSystemLookup, signal } from '@actor-system/core';
3
3
  import { generateMonotonicULID } from './__bundle__/shared/dist/monotonicULID.js';
4
4
  import { AskTimeoutError } from './errors.js';
5
5
 
@@ -21,7 +21,9 @@ const _askWithCallback = (options) => {
21
21
  replyTo.tell(new AskTimeoutError(`Ask to '${to.path}' timed out after ${timeout}ms`, to, timeout));
22
22
  }, Math.max(0, timeout));
23
23
  }
24
- const replyTo = to[$system].systemActorOf(receiveMessage((msg) => {
24
+ if (!isSystemLookup(to))
25
+ throw new Error(`Ask target ${to.path} must be a system bound actor`);
26
+ const replyTo = to._getSystem().systemActorOf(receiveMessage((msg) => {
25
27
  if (!(msg instanceof AskTimeoutError) && !done) {
26
28
  clearTimeout(timer);
27
29
  callback(msg);
package/dist/ask.d.ts CHANGED
@@ -1,12 +1,6 @@
1
1
  import { ActorRef } from '@actor-system/core';
2
2
  import { CreateRequest } from './ask-with-callback.js';
3
3
 
4
- interface AskOptions<Req, Res> {
5
- timeout?: number;
6
- to: ActorRef<Req>;
7
- request: CreateRequest<Req, Res>;
8
- }
9
- declare const ask: <const Req, Res>(options: AskOptions<Req, Res>) => Promise<Res>;
4
+ declare const ask: <const Req, Res>(to: ActorRef<Req>, request: CreateRequest<Req, Res>, timeout?: number) => Promise<Res>;
10
5
 
11
6
  export { ask };
12
- export type { AskOptions };
@@ -1,12 +1,6 @@
1
1
  import { ActorRef } from '@actor-system/core/internal';
2
2
  import { CreateRequest } from './ask-with-callback.internal.js';
3
3
 
4
- interface AskOptions<Req, Res> {
5
- timeout?: number;
6
- to: ActorRef<Req>;
7
- request: CreateRequest<Req, Res>;
8
- }
9
- declare const ask: <const Req, Res>(options: AskOptions<Req, Res>) => Promise<Res>;
4
+ declare const ask: <const Req, Res>(to: ActorRef<Req>, request: CreateRequest<Req, Res>, timeout?: number) => Promise<Res>;
10
5
 
11
6
  export { ask };
12
- export type { AskOptions };
package/dist/ask.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { _askWithCallback } from './ask-with-callback.js';
2
2
  import { AskTimeoutError } from './errors.js';
3
3
 
4
- const ask = (options) => new Promise((resolve, reject) => _askWithCallback({
5
- timeout: 1000,
6
- ...options,
4
+ const ask = (to, request, timeout = 1000) => new Promise((resolve, reject) => _askWithCallback({
5
+ timeout,
6
+ to,
7
+ request,
7
8
  callback: (response) => {
8
9
  if (response instanceof AskTimeoutError) {
9
10
  reject(response);
package/dist/errors.d.ts CHANGED
@@ -4,7 +4,6 @@ import { Letter } from '@actor-system/mail';
4
4
  declare const $timeoutError = "@@ask.timeout-error";
5
5
  declare const $unsupportedSyncOperationError = "@@ask.unsupported-sync-operation-error";
6
6
  declare const $noSynchronousResponseError = "@@ask.no-synchronous-response-error";
7
- declare const $reentryError = "@@ask.reentry-error";
8
7
  declare const $disconnectedError = "@@ask.disconnected-error";
9
8
  declare class AskTimeoutError extends Error implements Letter<typeof $timeoutError> {
10
9
  readonly label: typeof $timeoutError;
@@ -35,12 +34,6 @@ declare class NoSynchronousResponseError extends Error implements Letter<typeof
35
34
  readonly to: ActorRef;
36
35
  constructor(message: string, to: ActorRef, from?: ActorRef);
37
36
  }
38
- declare class ReentryError extends Error implements Letter<typeof $reentryError> {
39
- readonly label: typeof $reentryError;
40
- readonly from?: ActorRef;
41
- readonly to: ActorRef;
42
- constructor(message: string, to: ActorRef, from?: ActorRef);
43
- }
44
37
  declare class DisconnectedError extends Error implements Letter<typeof $disconnectedError> {
45
38
  readonly label: typeof $disconnectedError;
46
39
  readonly from?: ActorRef;
@@ -48,4 +41,4 @@ declare class DisconnectedError extends Error implements Letter<typeof $disconne
48
41
  constructor(message: string, to: ActorRef, from?: ActorRef);
49
42
  }
50
43
 
51
- export { $disconnectedError, $noSynchronousResponseError, $reentryError, $timeoutError, $unsupportedSyncOperationError, AskTimeoutError, DisconnectedError, NoSynchronousResponseError, ReentryError, UnsupportedSyncOperationError };
44
+ export { $disconnectedError, $noSynchronousResponseError, $timeoutError, $unsupportedSyncOperationError, AskTimeoutError, DisconnectedError, NoSynchronousResponseError, UnsupportedSyncOperationError };
@@ -4,7 +4,6 @@ import { Letter } from '@actor-system/mail/internal';
4
4
  declare const $timeoutError = "@@ask.timeout-error";
5
5
  declare const $unsupportedSyncOperationError = "@@ask.unsupported-sync-operation-error";
6
6
  declare const $noSynchronousResponseError = "@@ask.no-synchronous-response-error";
7
- declare const $reentryError = "@@ask.reentry-error";
8
7
  declare const $disconnectedError = "@@ask.disconnected-error";
9
8
  declare class AskTimeoutError extends Error implements Letter<typeof $timeoutError> {
10
9
  readonly label: typeof $timeoutError;
@@ -35,12 +34,6 @@ declare class NoSynchronousResponseError extends Error implements Letter<typeof
35
34
  readonly to: ActorRef;
36
35
  constructor(message: string, to: ActorRef, from?: ActorRef);
37
36
  }
38
- declare class ReentryError extends Error implements Letter<typeof $reentryError> {
39
- readonly label: typeof $reentryError;
40
- readonly from?: ActorRef;
41
- readonly to: ActorRef;
42
- constructor(message: string, to: ActorRef, from?: ActorRef);
43
- }
44
37
  declare class DisconnectedError extends Error implements Letter<typeof $disconnectedError> {
45
38
  readonly label: typeof $disconnectedError;
46
39
  readonly from?: ActorRef;
@@ -48,4 +41,4 @@ declare class DisconnectedError extends Error implements Letter<typeof $disconne
48
41
  constructor(message: string, to: ActorRef, from?: ActorRef);
49
42
  }
50
43
 
51
- export { $disconnectedError, $noSynchronousResponseError, $reentryError, $timeoutError, $unsupportedSyncOperationError, AskTimeoutError, DisconnectedError, NoSynchronousResponseError, ReentryError, UnsupportedSyncOperationError };
44
+ export { $disconnectedError, $noSynchronousResponseError, $timeoutError, $unsupportedSyncOperationError, AskTimeoutError, DisconnectedError, NoSynchronousResponseError, UnsupportedSyncOperationError };
package/dist/errors.js CHANGED
@@ -1,7 +1,6 @@
1
1
  const $timeoutError = "@@ask.timeout-error";
2
2
  const $unsupportedSyncOperationError = "@@ask.unsupported-sync-operation-error";
3
3
  const $noSynchronousResponseError = "@@ask.no-synchronous-response-error";
4
- const $reentryError = "@@ask.reentry-error";
5
4
  const $disconnectedError = "@@ask.disconnected-error";
6
5
  class AskTimeoutError extends Error {
7
6
  label = $timeoutError;
@@ -48,17 +47,6 @@ class NoSynchronousResponseError extends Error {
48
47
  this.to = to;
49
48
  }
50
49
  }
51
- class ReentryError extends Error {
52
- label = $reentryError;
53
- from;
54
- to;
55
- constructor(message, to, from) {
56
- super(message);
57
- this.name = "ReentryError";
58
- this.from = from;
59
- this.to = to;
60
- }
61
- }
62
50
  class DisconnectedError extends Error {
63
51
  label = $disconnectedError;
64
52
  from;
@@ -71,4 +59,4 @@ class DisconnectedError extends Error {
71
59
  }
72
60
  }
73
61
 
74
- export { $disconnectedError, $noSynchronousResponseError, $reentryError, $timeoutError, $unsupportedSyncOperationError, AskTimeoutError, DisconnectedError, NoSynchronousResponseError, ReentryError, UnsupportedSyncOperationError };
62
+ export { $disconnectedError, $noSynchronousResponseError, $timeoutError, $unsupportedSyncOperationError, AskTimeoutError, DisconnectedError, NoSynchronousResponseError, UnsupportedSyncOperationError };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { AskSyncOptions, askSync } from './ask-sync.js';
2
- export { AskOptions, ask } from './ask.js';
3
- export { $disconnectedError, $noSynchronousResponseError, $reentryError, $timeoutError, $unsupportedSyncOperationError, AskTimeoutError, DisconnectedError, NoSynchronousResponseError, ReentryError, UnsupportedSyncOperationError } from './errors.js';
1
+ export { askSync } from './ask-sync.js';
2
+ export { ask } from './ask.js';
3
+ export { $disconnectedError, $noSynchronousResponseError, $timeoutError, $unsupportedSyncOperationError, AskTimeoutError, DisconnectedError, NoSynchronousResponseError, UnsupportedSyncOperationError } from './errors.js';
4
4
  export { Ask, MapResponse, WithAskOptions, withAsk } from './use-ask.js';
@@ -1,4 +1,4 @@
1
- export { AskSyncOptions, askSync } from './ask-sync.internal.js';
2
- export { AskOptions, ask } from './ask.internal.js';
3
- export { $disconnectedError, $noSynchronousResponseError, $reentryError, $timeoutError, $unsupportedSyncOperationError, AskTimeoutError, DisconnectedError, NoSynchronousResponseError, ReentryError, UnsupportedSyncOperationError } from './errors.internal.js';
1
+ export { askSync } from './ask-sync.internal.js';
2
+ export { ask } from './ask.internal.js';
3
+ export { $disconnectedError, $noSynchronousResponseError, $timeoutError, $unsupportedSyncOperationError, AskTimeoutError, DisconnectedError, NoSynchronousResponseError, UnsupportedSyncOperationError } from './errors.internal.js';
4
4
  export { Ask, MapResponse, WithAskOptions, withAsk } from './use-ask.internal.js';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export { askSync } from './ask-sync.js';
2
2
  export { ask } from './ask.js';
3
- export { $disconnectedError, $noSynchronousResponseError, $reentryError, $timeoutError, $unsupportedSyncOperationError, AskTimeoutError, DisconnectedError, NoSynchronousResponseError, ReentryError, UnsupportedSyncOperationError } from './errors.js';
3
+ export { $disconnectedError, $noSynchronousResponseError, $timeoutError, $unsupportedSyncOperationError, AskTimeoutError, DisconnectedError, NoSynchronousResponseError, UnsupportedSyncOperationError } from './errors.js';
4
4
  export { withAsk } from './use-ask.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@actor-system/ask",
3
- "version": "0.0.18",
3
+ "version": "0.1.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "type-check": "tsc -b src",
@@ -34,12 +34,13 @@
34
34
  "@actor-system/shared"
35
35
  ],
36
36
  "dependencies": {
37
- "@actor-system/behaviors": "0.0.18",
38
- "@actor-system/core": "0.1.2",
39
- "@actor-system/mail": "0.0.3"
37
+ "@actor-system/behaviors": "0.1.0",
38
+ "@actor-system/core": "0.2.0",
39
+ "@actor-system/mail": "0.0.3",
40
+ "@actor-system/scheduler": "0.1.0"
40
41
  },
41
42
  "devDependencies": {
42
- "@actor-system/testing": "0.0.2",
43
+ "@actor-system/testing": "0.1.0",
43
44
  "@actor-system/shared": "0.0.3",
44
45
  "config": "^1.0.0"
45
46
  }