Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async Actor #3233

Merged
merged 48 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
495f45d
Initial concept
HarelM Oct 18, 2023
3c368b0
More improvements
HarelM Oct 20, 2023
f850217
Fix lint
HarelM Oct 20, 2023
1cef230
Main commit to move most of the actor code to use promises and regist…
HarelM Oct 21, 2023
ba3831a
Fix actor tests
HarelM Oct 22, 2023
b485c9b
Remove more any when it comes to worker self typings.
HarelM Oct 22, 2023
0dca144
Improve more types, add more tests
HarelM Oct 22, 2023
931e11b
Improve more types, add more tests
HarelM Oct 22, 2023
7f983e1
Fix lint
HarelM Oct 22, 2023
614524c
Fix more tests
HarelM Oct 22, 2023
4292d0a
Fix tests
HarelM Oct 22, 2023
5734e5e
Fix some sytle tests
HarelM Oct 22, 2023
af2aabb
Add comment for todo.
HarelM Oct 22, 2023
210c425
Fix test related to message parameters change
HarelM Oct 23, 2023
746fe2d
Fix remaining tests
HarelM Oct 23, 2023
8d19b99
Added todo to accomodate for code review.
HarelM Oct 23, 2023
35a58bd
Fix build test
HarelM Oct 23, 2023
62a6a4a
Merge branch 'main' into async-actor
HarelM Oct 23, 2023
9451485
Fix geojson types
HarelM Oct 23, 2023
af73f12
Rename some events, remove clutter a bit
HarelM Oct 23, 2023
6b2c265
Fix issue with multiple maps found in integration tests
HarelM Oct 23, 2023
7a1c9a8
Fix tests and improve types and docs a bit more
HarelM Oct 23, 2023
a18507b
Final fixes to make the tests pass
HarelM Oct 23, 2023
b92e486
Fix build test
HarelM Oct 23, 2023
3a2fdfc
a couple of tweaks (#3267)
msbarry Oct 24, 2023
a365145
Merge remote-tracking branch 'origin/main' into async-actor
HarelM Oct 24, 2023
712cf53
Merge branch 'main' into async-actor
HarelM Oct 24, 2023
fe8e847
Add changelog item
HarelM Oct 24, 2023
23db865
More improvement to async `Actor` and replace more callbacks with pro…
HarelM Oct 25, 2023
b045e38
Replace getJson call with async code and remove more callbacks (#3273)
HarelM Oct 27, 2023
2893ab3
Move image queue to use promises, move getArrayBuffer to use promises…
HarelM Oct 30, 2023
8259409
Remove TODOs, tidy up last things (#3301)
HarelM Nov 2, 2023
837695c
Merge branch 'main' into async-actor
HarelM Nov 2, 2023
5e4cdde
Async actor docs additions (#3305)
HarelM Nov 7, 2023
3c374d6
Merge branch 'main' into async-actor
HarelM Nov 7, 2023
4513eb6
Improve docs for RTL plugin status and reduce code in geojson worker …
HarelM Nov 7, 2023
2a773bf
Last simplification to actor, simplify a style test.
HarelM Nov 7, 2023
001b7a8
Add missing docs comments
HarelM Nov 7, 2023
c63e731
Fix lint...
HarelM Nov 7, 2023
5b2b2bd
Fix Actor XSS, introduce subscribe (#3329)
HarelM Nov 10, 2023
4d99526
Fix developer diagram with updated flow
HarelM Nov 13, 2023
c944799
Merge branch 'main' into async-actor
HarelM Nov 14, 2023
da95a03
Async actor no log warnings and errors in unit tests (#3368)
HarelM Nov 15, 2023
9feae22
Async actor remove cancelables (#3371)
HarelM Nov 15, 2023
6c90f58
Merge branch 'main' into async-actor
HarelM Nov 22, 2023
78bb4a3
Async actor callback and promise (#3374)
HarelM Nov 22, 2023
40846ff
Merge branch 'main' into async-actor
HarelM Nov 23, 2023
3fbff23
Update changelog with most of the changes
HarelM Nov 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/data/dem_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {register} from '../util/web_worker_transfer';
export type DEMEncoding = 'mapbox' | 'terrarium' | 'custom'

export class DEMData {
uid: string;
uid: string | number;
data: Uint32Array;
stride: number;
dim: number;
Expand All @@ -29,7 +29,7 @@ export class DEMData {

// RGBAImage data has uniform 1px padding on all sides: square tile edge size defines stride
// and dim is calculated as stride - 2.
constructor(uid: string, data: RGBAImage, encoding: DEMEncoding, redFactor = 1.0, greenFactor = 1.0, blueFactor = 1.0, baseShift = 0.0) {
constructor(uid: string | number, data: RGBAImage, encoding: DEMEncoding, redFactor = 1.0, greenFactor = 1.0, blueFactor = 1.0, baseShift = 0.0) {
this.uid = uid;
if (data.height !== data.width) throw new RangeError('DEM tiles must be square');
if (encoding && !['mapbox', 'terrarium', 'custom'].includes(encoding)) {
Expand Down
111 changes: 60 additions & 51 deletions src/source/geojson_source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const wrapDispatcher = (dispatcher) => {
};

const mockDispatcher = wrapDispatcher({
send() {}
sendAsync() { return Promise.resolve({}); }
});

const hawkHill = {
Expand Down Expand Up @@ -58,10 +58,10 @@ describe('GeoJSONSource#setData', () => {
opts = opts || {};
opts = extend(opts, {data: {}});
return new GeoJSONSource('id', opts, wrapDispatcher({
send (type, data, callback) {
if (callback) {
return setTimeout(callback, 0);
}
sendAsync(_message) {
return new Promise((resolve) => {
setTimeout(() => resolve({}), 0);
});
}
}), undefined);
}
Expand Down Expand Up @@ -91,8 +91,10 @@ describe('GeoJSONSource#setData', () => {

test('fires "dataabort" event', done => {
const source = new GeoJSONSource('id', {} as any, wrapDispatcher({
send(type, data, callback) {
setTimeout(() => callback(null, {abandoned: true}));
sendAsync(_message) {
return new Promise((resolve) => {
setTimeout(() => resolve({abandoned: true}), 0);
});
}
}), undefined);
source.on('dataabort', () => {
Expand All @@ -108,13 +110,15 @@ describe('GeoJSONSource#setData', () => {
transformRequest: (url) => { return {url}; }
} as any as RequestManager
} as any;
source.actor.send = function(type, params: any, cb) {
if (type === 'geojson.loadData') {
expect(params.request.collectResourceTiming).toBeTruthy();
setTimeout(cb, 0);
done();
}
} as any;
source.actor.sendAsync = (message) => {
return new Promise((resolve) => {
if (message.type === 'geojson.loadData') {
expect((message.data as any).request.collectResourceTiming).toBeTruthy();
setTimeout(() => resolve({} as any), 0);
done();
}
});
};
source.setData('http://localhost/nonexistent');
});

Expand Down Expand Up @@ -148,8 +152,10 @@ describe('GeoJSONSource#setData', () => {

test('marks source as loaded before firing "dataabort" event', done => {
const source = new GeoJSONSource('id', {} as any, wrapDispatcher({
send(type, data, callback) {
setTimeout(() => callback(null, {abandoned: true}));
sendAsync(_message) {
return new Promise((resolve) => {
setTimeout(() => resolve({abandoned: true}), 0);
});
}
}), undefined);
source.on('dataabort', () => {
Expand All @@ -163,11 +169,11 @@ describe('GeoJSONSource#setData', () => {
describe('GeoJSONSource#onRemove', () => {
test('broadcasts "removeSource" event', done => {
const source = new GeoJSONSource('id', {data: {}} as GeoJSONSourceOptions, wrapDispatcher({
send(type, data, callback) {
expect(callback).toBeFalsy();
expect(type).toBe('removeSource');
expect(data).toEqual({type: 'geojson', source: 'id'});
sendAsync(message) {
expect(message.type).toBe('removeSource');
expect(message.data).toEqual({type: 'geojson', source: 'id'});
done();
return Promise.resolve({});
},
broadcast() {
// Ignore
Expand All @@ -187,9 +193,10 @@ describe('GeoJSONSource#update', () => {

test('sends initial loadData request to dispatcher', done => {
const mockDispatcher = wrapDispatcher({
send(message) {
expect(message).toBe('geojson.loadData');
sendAsync(message) {
expect(message.type).toBe('geojson.loadData');
done();
return Promise.resolve({});
}
});

Expand All @@ -198,9 +205,9 @@ describe('GeoJSONSource#update', () => {

test('forwards geojson-vt options with worker request', done => {
const mockDispatcher = wrapDispatcher({
send(message, params) {
expect(message).toBe('geojson.loadData');
expect(params.geojsonVtOptions).toEqual({
sendAsync(message) {
expect(message.type).toBe('geojson.loadData');
expect(message.data.geojsonVtOptions).toEqual({
extent: 8192,
maxZoom: 10,
tolerance: 4,
Expand All @@ -209,6 +216,7 @@ describe('GeoJSONSource#update', () => {
generateId: true
});
done();
return Promise.resolve({});
}
});

Expand All @@ -223,9 +231,9 @@ describe('GeoJSONSource#update', () => {

test('forwards Supercluster options with worker request', done => {
const mockDispatcher = wrapDispatcher({
send(message, params) {
expect(message).toBe('geojson.loadData');
expect(params.superclusterOptions).toEqual({
sendAsync(message) {
expect(message.type).toBe('geojson.loadData');
expect(message.data.superclusterOptions).toEqual({
maxZoom: 12,
minPoints: 3,
extent: 8192,
Expand All @@ -234,6 +242,7 @@ describe('GeoJSONSource#update', () => {
generateId: true
});
done();
return Promise.resolve({});
}
});

Expand All @@ -250,12 +259,13 @@ describe('GeoJSONSource#update', () => {
test('modifying cluster properties after adding a source', done => {
// test setCluster function on GeoJSONSource
const mockDispatcher = wrapDispatcher({
send(message, params) {
expect(message).toBe('geojson.loadData');
expect(params.cluster).toBe(true);
expect(params.superclusterOptions.radius).toBe(80);
expect(params.superclusterOptions.maxZoom).toBe(16);
sendAsync(message) {
expect(message.type).toBe('geojson.loadData');
expect(message.data.cluster).toBe(true);
expect(message.data.superclusterOptions.radius).toBe(80);
expect(message.data.superclusterOptions.maxZoom).toBe(16);
done();
return Promise.resolve({});
}
});
new GeoJSONSource('id', {
Expand All @@ -270,9 +280,9 @@ describe('GeoJSONSource#update', () => {

test('forwards Supercluster options with worker request, ignore max zoom of source', done => {
const mockDispatcher = wrapDispatcher({
send(message, params) {
expect(message).toBe('geojson.loadData');
expect(params.superclusterOptions).toEqual({
sendAsync(message) {
expect(message.type).toBe('geojson.loadData');
expect(message.data.superclusterOptions).toEqual({
maxZoom: 12,
minPoints: 3,
extent: 8192,
Expand All @@ -281,6 +291,7 @@ describe('GeoJSONSource#update', () => {
generateId: true
});
done();
return Promise.resolve({});
}
});

Expand Down Expand Up @@ -309,10 +320,10 @@ describe('GeoJSONSource#update', () => {
});
test('fires event when metadata loads', done => {
const mockDispatcher = wrapDispatcher({
send(message, args, callback) {
if (callback) {
setTimeout(callback, 0);
}
sendAsync(_message) {
return new Promise((resolve) => {
setTimeout(() => resolve({}), 0);
});
}
});

Expand All @@ -328,8 +339,10 @@ describe('GeoJSONSource#update', () => {
test('fires metadata data event even when initial request is aborted', done => {
let requestCount = 0;
const mockDispatcher = wrapDispatcher({
send(message, args, callback) {
setTimeout(() => callback(null, {abandoned: requestCount++ === 0}));
sendAsync(_message) {
return new Promise((resolve) => {
setTimeout(() => resolve({abandoned: requestCount++ === 0}));
});
}
});

Expand All @@ -345,10 +358,8 @@ describe('GeoJSONSource#update', () => {

test('fires "error"', done => {
const mockDispatcher = wrapDispatcher({
send(message, args, callback) {
if (callback) {
setTimeout(callback.bind(null, 'error'), 0);
}
sendAsync(_message) {
return Promise.reject('error'); // eslint-disable-line prefer-promise-reject-errors
}
});

Expand All @@ -365,13 +376,11 @@ describe('GeoJSONSource#update', () => {
test('sends loadData request to dispatcher after data update', done => {
let expectedLoadDataCalls = 2;
const mockDispatcher = wrapDispatcher({
send(message, args, callback) {
if (message === 'geojson.loadData' && --expectedLoadDataCalls <= 0) {
sendAsync(message) {
if (message.type === 'geojson.loadData' && --expectedLoadDataCalls <= 0) {
done();
}
if (callback) {
setTimeout(callback, 0);
}
return new Promise((resolve) => setTimeout(() => resolve({}), 0));
}
});

Expand Down