Skip to content

Commit

Permalink
Merged PR 275046: changed broadcast to return promise<void>
Browse files Browse the repository at this point in the history
changed broadcast to return promise<void>
  • Loading branch information
asibross authored and Asi Bross committed May 23, 2017
1 parent 5d8958f commit fb8175f
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 399 deletions.
19 changes: 14 additions & 5 deletions lib/runtime/napa-zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,27 @@ export class NapaZone implements zone.Zone {
return { id: this.id, type: "napa" };
}

public broadcast(arg1: any, arg2?: any) : Promise<zone.ResponseCode> {
public broadcast(arg1: any, arg2?: any) : Promise<void> {
let source: string = this.createBroadcastSource(arg1, arg2);

return new Promise<zone.ResponseCode>(resolve => {
this._nativeZone.broadcast(source, resolve);
return new Promise<void>((resolve, reject) => {
this._nativeZone.broadcast(source, (responseCode: number) => {
if (responseCode === 0) {
resolve();
} else {
reject("broadcast failed with response code: " + responseCode);
}
});
});
}

public broadcastSync(arg1: any, arg2?: any) : zone.ResponseCode {
public broadcastSync(arg1: any, arg2?: any) : void {
let source: string = this.createBroadcastSource(arg1, arg2);

return this._nativeZone.broadcastSync(source);
let responseCode: number = this._nativeZone.broadcastSync(source);
if (responseCode !== 0) {
throw new Error("broadcast failed with response code: " + responseCode);
}
}

public execute(arg1: any, arg2: any, arg3?: any, arg4?: any) : Promise<zone.ExecuteResult> {
Expand Down
5 changes: 2 additions & 3 deletions lib/runtime/node-zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ export class NodeZone implements zone.Zone {
return { id: this.id, type: "node" };
}

public broadcast(arg1: any, arg2?: any) : Promise<zone.ResponseCode> {
public broadcast(arg1: any, arg2?: any) : Promise<void> {
// TODO @asib: add implementation
return undefined;
}

public broadcastSync(arg1: any, arg2?: any) : zone.ResponseCode {
public broadcastSync(arg1: any, arg2?: any) : void {
// TODO @asib: add implementation
return undefined;
}

public execute(arg1: any, arg2: any, arg3?: any, arg4?: any) : Promise<zone.ExecuteResult> {
Expand Down
11 changes: 4 additions & 7 deletions lib/runtime/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ export interface ZoneSettings {
workers?: number;
}

/// <summary> The type of the response code. </summary>
export type ResponseCode = number;

/// <summary> Represent the result of an execute call. </summary>
export interface ExecuteResult {

Expand All @@ -31,14 +28,14 @@ export interface Zone {

/// <summary> Compiles and run the provided source code on all zone workers. </summary>
/// <param name="source"> A valid javascript source code. </param>
broadcast(source: string) : Promise<ResponseCode>;
broadcastSync(source: string) : ResponseCode;
broadcast(source: string) : Promise<void>;
broadcastSync(source: string) : void;

/// <summary> Compiles the function on all workers and runs it with the given arguments. </summary>
/// <param name="func"> The JS function. </param>
/// <param name="args"> The arguments that will pass to the function. </param>
broadcast(func: Function, args: any[]) : Promise<ResponseCode>;
broadcastSync(func: Function, args: any[]) : ResponseCode;
broadcast(func: Function, args: any[]) : Promise<void>;
broadcastSync(func: Function, args: any[]) : void;

/// <summary> Executes the function on one of the zone workers. </summary>
/// <param name="module"> The module name that contains the function to execute. </param>
Expand Down
Loading

0 comments on commit fb8175f

Please sign in to comment.