Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/js-client/src/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ describe("User API methods", () => {
args: {},
peer,
script,
fireAndForget: false,
});

expect(res).toBe(7);
Expand Down
1 change: 1 addition & 0 deletions packages/core/js-client/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export const v5_callFunction = async (
peer: peerOrArg,
args: callArgs,
config,
fireAndForget: returnTypeVoid,
});

if (returnTypeVoid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe("FluenceClient usage test suite", () => {
},
});

peer.internals.initiateParticle(particle, resolve, reject);
peer.internals.initiateParticle(particle, resolve, reject, false);
});

await expect(promise).rejects.toThrow(ExpirationError);
Expand Down
4 changes: 3 additions & 1 deletion packages/core/js-client/src/compilerSupport/callFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export type CallAquaFunctionArgs = {
config?: CallAquaFunctionConfig | undefined;
peer: FluencePeer;
args: { [key: string]: JSONValue | ArgCallbackFunction };
fireAndForget: boolean;
};

export type CallAquaFunctionConfig = {
Expand All @@ -60,6 +61,7 @@ export const callAquaFunction = async ({
config = {},
peer,
args,
fireAndForget,
}: CallAquaFunctionArgs) => {
log.trace("calling aqua function %j", { script, config, args });

Expand All @@ -85,6 +87,6 @@ export const callAquaFunction = async ({

registerParticleScopeService(peer, particle, errorHandlingService(reject));

peer.internals.initiateParticle(particle, resolve, reject);
peer.internals.initiateParticle(particle, resolve, reject, fireAndForget);
});
};
6 changes: 6 additions & 0 deletions packages/core/js-client/src/jsPeer/FluencePeer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,13 @@ export abstract class FluencePeer {
* @param particle - particle to start execution of
* @param onSuccess - callback which is called when particle execution succeed
* @param onError - callback which is called when particle execution fails
* @param fireAndForget - determines whether particle has fire-and-forget behavior
*/
initiateParticle: (
particle: IParticle,
onSuccess: (result: JSONValue) => void,
onError: (error: Error) => void,
fireAndForget: boolean = true,
): void => {
if (!this.isInitialized) {
throw new Error(
Expand All @@ -278,6 +280,7 @@ export abstract class FluencePeer {
callResults: [],
onSuccess,
onError,
fireAndForget,
});
},

Expand Down Expand Up @@ -607,6 +610,9 @@ export abstract class FluencePeer {
if (item.result.callRequests.length > 0) {
// TS doesn't allow to pass just 'item'
void this.execCallRequests({ ...item, result: item.result });
} else if (item.fireAndForget === true) {
// Local work done.
item.onSuccess(null);
}

return connectionPromise;
Expand Down
1 change: 1 addition & 0 deletions packages/core/js-client/src/particle/Particle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export interface ParticleQueueItem {
callResults: CallResultsArray;
onSuccess: (result: JSONValue) => void;
onError: (error: Error) => void;
fireAndForget?: boolean;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions packages/core/js-client/src/util/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,18 @@ export const compileAqua = async (aquaFile: string): Promise<CompiledFile> => {
const functions = Object.entries(compilationResult.functions)
.map(([name, fnInfo]: [string, FunctionInfo]) => {
const callFn = (peer: FluencePeer, args: PassedArgs) => {
const def = fnInfo.funcDef;

const isReturnTypeVoid =
def.arrow.codomain.tag === "nil" ||
def.arrow.codomain.items.length === 0;

return callAquaFunction({
script: fnInfo.script,
config: {},
peer: peer,
args,
fireAndForget: isReturnTypeVoid,
});
};

Expand Down