Skip to content

Commit 1c2ab2a

Browse files
ivanbuhovPanayotCankov
authored andcommitted
Add typescript declarations for workers
1 parent ffc611c commit 1c2ab2a

File tree

4 files changed

+93
-3
lines changed

4 files changed

+93
-3
lines changed

gruntfile.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ module.exports = function(grunt) {
115115
"!tns-core-modules.es6.d.ts",
116116
"!tns-core-modules.es2016.d.ts",
117117
"!tns-core-modules.base.d.ts",
118-
"!references.d.ts"
118+
"!references.d.ts",
119+
"!webworker.es2016.d.ts"
119120
].concat(localCfg.defaultExcludes).concat(es6Excludes).concat(angularExcludes));
120121
dtsFiles.sort();
121122

@@ -266,7 +267,7 @@ module.exports = function(grunt) {
266267
"!android17.d.ts",
267268
"!**/*.android.d.ts",
268269
"!ios.d.ts",
269-
"!**/*.ios.d.ts",
270+
"!**/*.ios.d.ts"
270271
].concat(localCfg.defaultExcludes),
271272
dest: localCfg.outDir + "/",
272273
expand: true,

tns-core-modules/declarations.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,4 @@ declare var exports: any;
165165

166166
interface Array<T> {
167167
filter<U extends T>(pred: (a: T) => a is U): U[];
168-
}
168+
}

tns-core-modules/tns-core-modules.es2016.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/// <reference path="./tns-core-modules.base.d.ts" />
2+
/// <reference path="./webworker.es2016.d.ts" />
23
/// <reference path="./module.d.ts" />
34
/// <reference path="./lib.dom.d.ts" />
45

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
2+
/**
3+
* Used to create, destroy and communicate with worker threads
4+
*/
5+
declare class Worker {
6+
7+
/**
8+
* Creates a new worker with the given main script.
9+
* @param script The first module to be loaded on the worker thread.
10+
*/
11+
public constructor(script: string);
12+
13+
/**
14+
* Sends message to the worker thread.
15+
* @param message The message to be serialized and sent to the worker thread.
16+
*/
17+
public postMessage(message: any) : void;
18+
19+
/**
20+
* Terminates the execution the worker thread without calling `onclose` handler.
21+
*/
22+
public terminate() : void;
23+
24+
/**
25+
* Called by the runtime when a new message is received by the worker instance.
26+
*/
27+
public onmessage : Worker.OnMessageHandler;
28+
29+
/**
30+
* Called by the runtime when an uncaught error is propagated to the parent thread.
31+
*/
32+
public onerror : Worker.OnErrorHandler;
33+
}
34+
35+
/**
36+
* Exists only in worker context. Returns the worker global object.
37+
*/
38+
declare var self: any;
39+
40+
/**
41+
* Exists only in worker context. It is called by the runtime when a new message is received by the worker thread.
42+
*/
43+
declare var onmessage : Worker.OnMessageHandler;
44+
45+
/**
46+
* Exists only in worker context. Handles uncaught errors in the worker thread. If return false the error is propagated to the parent context and passed to Worker.onerror handler.
47+
*/
48+
declare var onerror : Worker.OnErrorHandler;
49+
50+
/**
51+
* Exists only in worker context. Called before the worker is closed with the close() function.
52+
*/
53+
declare var onclose : Worker.OnCloseHandler;
54+
55+
/**
56+
* Exists only in worker context. Sends message to the parent thread.
57+
*/
58+
declare function postMessage(message: any) : void;
59+
60+
/**
61+
* Exists only in worker context. Closes the worker thread on the next run loop tick.
62+
*/
63+
declare function close() : void;
64+
65+
declare namespace Worker {
66+
67+
interface MessageEvent {
68+
data: any;
69+
}
70+
71+
interface ErrorEvent {
72+
message: string;
73+
filename: string;
74+
lineno: number;
75+
}
76+
77+
interface OnErrorHandler {
78+
(error: ErrorEvent): boolean;
79+
}
80+
81+
interface OnMessageHandler {
82+
(message: MessageEvent): void;
83+
}
84+
85+
interface OnCloseHandler {
86+
(): void;
87+
}
88+
}

0 commit comments

Comments
 (0)