-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: AppWorkerClient subscribe same data failed issue (#110)
- Loading branch information
Showing
6 changed files
with
285 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
module.exports = function initAgent(agent) { | ||
const client = { | ||
'mock-data': 'mock-data', | ||
'not-exist-data': null, | ||
ready(cb) { | ||
setImmediate(cb); | ||
}, | ||
}; | ||
|
||
agent.startAgent({ | ||
name: 'sub-client', | ||
client, | ||
subscribe(info, listener) { | ||
listener(client[info]); | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
|
||
module.exports = function initApp(app) { | ||
app.subClient = app.createAppWorkerClient('sub-client', { | ||
subscribe(info, listener) { | ||
this._subscribe(info, listener); | ||
return this; | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
module.exports = function(app) { | ||
const done = app.readyCallback('app_subscribe_data'); | ||
app.subClient.subscribe('mock-data', val => { | ||
app.mockData = val; | ||
done(); | ||
}); | ||
|
||
const done1 = app.readyCallback('app_subscribe_not_exist_data'); | ||
app.subClient.subscribe('not-exist-data', val => { | ||
app.notExistData = val; | ||
done1(); | ||
}); | ||
|
||
app.get('/', function*() { | ||
const val = yield cb => app.subClient.subscribe('mock-data', val => { | ||
cb(null, val); | ||
}); | ||
|
||
this.body = { | ||
'mock-data': val, | ||
'app-mock-data': app.mockData, | ||
}; | ||
}); | ||
|
||
app.get('/not-exist', function*() { | ||
const val = yield cb => app.subClient.subscribe('not-exist-data', val => { | ||
cb(null, val); | ||
}); | ||
|
||
this.body = { | ||
'not-exist-data': null, | ||
'app-not-exist-data': null, | ||
}; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "agent-client-app" | ||
} |
Oops, something went wrong.