-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lib): add OptEventHandler for subscribing to events move WS to i…
…nstance shift toward subscribing to events at the point of instance construction with an option to provide an event handler & event type subscription list as a NewInstance option. While we're at it, let's internalize the websocket connection, which might actually be able to replace the RPC api in the long run? either way it lets a bunch of fields remain unexported.
- Loading branch information
Showing
6 changed files
with
119 additions
and
26 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,6 @@ | ||
package event | ||
|
||
|
||
// ETInstanceConstructed is fired once a node is created | ||
// payload is nil | ||
var ETInstanceConstructed = Type("lib:InstanceConstructed") |
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
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,43 @@ | ||
package lib | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/qri-io/qfs" | ||
"github.com/qri-io/qri/config" | ||
repotest "github.com/qri-io/qri/repo/test" | ||
) | ||
|
||
func TestWebsocket(t *testing.T) { | ||
tr, err := repotest.NewTempRepo("foo", "websocket_test", repotest.NewTestCrypto()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer tr.Delete() | ||
|
||
instCtx, instCancel := context.WithCancel(context.Background()) | ||
defer instCancel() | ||
|
||
cfg := config.DefaultConfigForTesting() | ||
cfg.Filesystems = []qfs.Config{ | ||
{Type: "mem"}, | ||
{Type: "local"}, | ||
} | ||
cfg.Repo.Type = "mem" | ||
|
||
inst, err := NewInstance(instCtx, tr.QriPath, OptConfig(cfg)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
wsCtx, wsCancel := context.WithCancel(context.Background()) | ||
done := make(chan struct{}) | ||
go func() { | ||
inst.ServeWebsocket(wsCtx) | ||
done <- struct{}{} | ||
}() | ||
|
||
wsCancel() | ||
<-done | ||
} |