Skip to content

Commit

Permalink
chore: update potoo etc
Browse files Browse the repository at this point in the history
  • Loading branch information
metasansana committed Oct 9, 2024
1 parent 29c41f9 commit 9fc9167
Show file tree
Hide file tree
Showing 74 changed files with 3,842 additions and 3,360 deletions.
11 changes: 11 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"singleQuote": true,
"trailingComma": "none",
"semi": true,
"bracketSpacing": true,
"tabWidth": 4,
"arrowParens": "avoid",
"useTabs": false,
"printWidth": 80,
"quoteProps": "as-needed"
}
2,711 changes: 2,151 additions & 560 deletions package-lock.json

Large diffs are not rendered by default.

21 changes: 13 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,25 @@
"@types/bluebird": "^3.5.29",
"@types/express": "^4.17.11",
"@types/express-session": "^1.17.3",
"@types/mocha": "^8.2.1",
"@types/mocha": "^10.0.7",
"@types/morgan": "^1.9.2",
"@types/node": "^14.18.5",
"@types/superagent": "^4.1.4",
"@types/node": "^20.14.12",
"@types/superagent": "^8.1.7",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"bluebird": "^3.7.2",
"body-parser": "^1.19.0",
"mocha": "^8.3.2",
"eslint": "^8.34.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-prettier": "^4.2.1",
"mocha": "^10.7.0",
"prettier": "^3.2.5",
"superagent": "^5.1.3",
"ts-node": "^8.9.1",
"typescript": "^4.2.3"
"ts-node": "^10.9.2",
"typescript": "^5.5.4"
},
"dependencies": {
"@quenk/noni": "^1.42.0",
"@quenk/potoo": "^3.1.7-0",
"@quenk/noni": "^1.52.12",
"@quenk/potoo": "^4.0.11",
"@types/body-parser": "^1.19.0",
"@types/cookie-parser": "^1.4.2",
"@types/csurf": "^1.9.36",
Expand Down
131 changes: 53 additions & 78 deletions src/app/api/control/actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,148 +3,124 @@ import { resolve } from 'path';
import { liftF } from '@quenk/noni/lib/control/monad/free';
import { Future, Run, pure } from '@quenk/noni/lib/control/monad/future';
import { compose, identity } from '@quenk/noni/lib/data/function';
import { Constructor } from '@quenk/noni/lib/data/type/constructor';
import { generateV4} from '@quenk/noni/lib/crypto/uuid';
import { generateV4 } from '@quenk/noni/lib/crypto/uuid';

import {
Callback as ResidentCallback
} from '@quenk/potoo/lib/actor/resident/immutable/callback';
import { Address } from '@quenk/potoo/lib/actor/address';
import { Message } from '@quenk/potoo/lib/actor/message';
import { Case } from '@quenk/potoo/lib/actor/resident/case';
import { Message } from '@quenk/potoo/lib/actor';

import { App } from '../../../app';
import { Api, Action, Context } from '../';

/**
* Self
* @private
*/
export class Self<N, A> extends Api<A> {

constructor(public next: (a: any) => A) { super(next); }
constructor(public next: (a: any) => A) {
super(next);
}

map<B>(f: (a: A) => B): Self<N, B> {

return new Self(compose(this.next, f));

}

exec(ctx: Context<A>): Future<A> {

return pure(this.next(ctx.module.self()));

return pure(this.next(ctx.module.self));
}

}

/**
* Tell
* Tell
* @private
*/
export class Tell<N, A> extends Api<A>{

export class Tell<N, A> extends Api<A> {
constructor(
public to: Address,
public message: Message,
public next: A) { super(next); }
public next: A
) {
super(next);
}

map<B>(f: (a: A) => B): Tell<N, B> {

return new Tell(this.to, this.message, f(this.next));

}

exec(ctx: Context<A>): Future<A> {

return pure(ctx.module.tell(this.to, this.message))
.map(() => this.next);

}

}

class Callback<A> extends ResidentCallback<A> {

constructor(
public pattern: Constructor<A>,
public f: (a: A) => void,
public app: App) { super(app); }

receive() {

return [new Case(this.pattern, (a: A) => { this.f(a); }) ];

}

run() {

return pure(ctx.module.tell(this.to, this.message)).map(
() => this.next
);
}

}

/**
* Request wraps a message to an actor in to indicate a reply is
* expected.
*/
export class Request<T> {

constructor(
public from: Address,
public message: T) { }

public message: T
) {}
}

/**
* Response to a Request
*/
export class Response<T> {

constructor(public value: T) { }

constructor(public value: T) {}
}

/**
* Ask
* @private
*/
export class Ask<N, A> extends Api<A> {

constructor(
public to: Address,
public message: Message,
public next: (a: any) => A) { super(next); }
public next: (a: any) => A
) {
super(next);
}

map<B>(f: (a: A) => B): Ask<N, B> {

return new Ask(this.to, this.message, compose(this.next, f));

}

exec(ctx: Context<A>): Future<A> {

let { to, message, next } = this;

return (<Future<A>>new Run<Message>(()=> new Promise((onSuccess) => {

let id = generateV4();
let cb = (t: Message) => onSuccess(t.value);

ctx.module.spawn({
id,
create: a => new Callback(Response, cb, <App>a)
});

ctx.module.tell(to,
new Request(resolve(`${ctx.module.self()}/${id}`), message));

return () => { }

})))
.chain(v => pure(next(v)));

return (<Future<A>>new Run<Message>(
() =>
new Promise(onSuccess => {
let id = generateV4();

ctx.module.spawn({
id,
run: async runtime => {
while (runtime.isValid()) {
let msg = await runtime.receive();

if (msg instanceof Response) {
onSuccess(msg.value);
break;
}
}
}
});

ctx.module.tell(
to,
new Request(
resolve(`${ctx.module.self}/${id}`),
message
)
);

return () => {};
})
)).chain(v => pure(next(v)));
}

}

/**
Expand All @@ -159,8 +135,7 @@ export const ask = <T>(to: Address, m: Message): Action<T> =>
/**
* self provides the address of the module.
*/
export const self = (): Action<Address> =>
liftF(new Self(identity));
export const self = (): Action<Address> => liftF(new Self(identity));

/**
* tell sends a message to another actor.
Expand Down
Loading

0 comments on commit 9fc9167

Please sign in to comment.