Skip to content

Commit

Permalink
ref: internalise (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed May 10, 2024
1 parent 5b1d674 commit f2e0a7b
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 99 deletions.
32 changes: 27 additions & 5 deletions core/core-defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,32 @@ package core
// core contains universal definitions and handles cross cutting concerns
// try to keep to a minimum to reduce rippling changes

type TraverseResult interface {
}
type (
// TraverseResult
TraverseResult interface {
}

type DuffResult struct {
}
// Client is the callback invoked for each file system node found
// during traversal.
Client func(node *Node) error
)

type Client func(node *Node) error
type (
// SimpleHandler is a function that takes no parameters and can
// be used by any notification with this signature.
SimpleHandler func()

// BeginHandler invoked before traversal begins
BeginHandler func(root string)

// EndHandler invoked at the end of traversal
EndHandler func(result TraverseResult)

// HibernateHandler is a generic handler that is used by hibernation
// to indicate wake or sleep.
HibernateHandler func(description string)

// NodeHandler is a generic handler that is for any notification that contains
// the traversal node, such as directory ascend or descend.
NodeHandler func(node *Node)
)
13 changes: 6 additions & 7 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/snivilised/extendio/bus"
"github.com/snivilised/traverse/core"
"github.com/snivilised/traverse/internal/services"
"github.com/snivilised/traverse/internal/types"
"github.com/snivilised/traverse/kernel"
"github.com/snivilised/traverse/pref"
Expand All @@ -22,18 +23,18 @@ type duffNavigator struct {
}

func (n *duffNavigator) Navigate() (core.TraverseResult, error) {
return core.DuffResult{}, nil
return types.NavigateResult{}, nil
}

func init() {
h := bus.Handler{
Handle: func(_ context.Context, m bus.Message) {
m.Data.(types.ContextExpiry).Expired()
},
Matcher: core.TopicContextExpired,
Matcher: services.TopicContextExpired,
}

core.Broker.RegisterHandler(badge, h)
services.Broker.RegisterHandler(badge, h)
}

// replaces the runner in extendio, although it not
Expand All @@ -54,11 +55,9 @@ func Walk() Driver {
}
}

func Run(options ...pref.Option) Driver {
func Run() Driver {
return &driver{
session: &session{
accelerationOptions: options,
},
session: &session{},
}
}

Expand Down
8 changes: 4 additions & 4 deletions hiber/hibernation-defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"

"github.com/snivilised/extendio/bus"
"github.com/snivilised/traverse/core"
"github.com/snivilised/traverse/internal/services"
)

const (
Expand All @@ -29,14 +29,14 @@ func init() {
//
_ = m.Data
},
Matcher: core.TopicOptionsAnnounce,
Matcher: services.TopicOptionsAnnounce,
}

core.Broker.RegisterHandler(badge, h)
services.Broker.RegisterHandler(badge, h)
}

// subscribe to options.before
func RestoreOptions() {
// called bny resume to load options from json file and
// called by resume to load options from json file and
// setup registry to reflect this
}
9 changes: 4 additions & 5 deletions core/broker.go → internal/services/broker.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package core
package services

import (
"github.com/snivilised/extendio/bus"
)
import "github.com/snivilised/extendio/bus"

const (
format = "%03d"
TopicContextExpired = "context.expired"
TopicOptionsAnnounce = "options.announce"
TopicOptionsBefore = "options.before"
TopicOptionsComplete = "options.complete"
TopicContextExpired = "context.expired"
)

var (
Broker *bus.Broker
topics = []string{
TopicContextExpired,
TopicOptionsAnnounce,
TopicOptionsBefore,
TopicOptionsComplete,
Expand Down
14 changes: 11 additions & 3 deletions internal/types/definitions.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package types

type ContextExpiry interface {
Expired() // ??? ctx context.Context, cancel context.CancelFunc
}
// package types

type (
ContextExpiry interface {
Expired() // ??? ctx context.Context, cancel context.CancelFunc
}

// NavigateResult
NavigateResult struct {
}
)
46 changes: 0 additions & 46 deletions kernel/options.go

This file was deleted.

6 changes: 3 additions & 3 deletions pref/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"runtime"

"github.com/snivilised/extendio/bus"
"github.com/snivilised/traverse/core"
"github.com/snivilised/traverse/cycle"
"github.com/snivilised/traverse/enums"
"github.com/snivilised/traverse/internal/services"
)

// package: pref contains user option definitions; do not use anything in kernel (cyclic)
Expand All @@ -22,10 +22,10 @@ func init() {
Handle: func(_ context.Context, m bus.Message) {
_ = m.Data
},
Matcher: core.TopicOptionsAnnounce,
Matcher: services.TopicOptionsAnnounce,
}

core.Broker.RegisterHandler(badge, h)
services.Broker.RegisterHandler(badge, h)
}

type (
Expand Down
9 changes: 3 additions & 6 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package traverse
import (
"context"
"time"

"github.com/snivilised/traverse/pref"
)

type Session interface {
Expand All @@ -13,10 +11,9 @@ type Session interface {
}

type session struct {
started time.Time
ctx context.Context
cancel context.CancelFunc
accelerationOptions []pref.Option
started time.Time
ctx context.Context
cancel context.CancelFunc
}

func (s *session) StartedAt() time.Time {
Expand Down
32 changes: 12 additions & 20 deletions traverse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ var _ = Describe("Traverse", func() {

_, err := traverse.Walk().Primary(
"/root-path",
func(node *core.Node) error {
_ = node

func(_ *core.Node) error {
return nil
},
pref.WithSubscription(enums.SubscribeFiles),
Expand Down Expand Up @@ -67,16 +65,13 @@ var _ = Describe("Traverse", func() {
// something like "context.expired"
//
ctx := context.Background()
_, err := traverse.Run(
pref.WithContext(ctx),
).Primary(
_, err := traverse.Run().Primary(
"/root-path",
func(node *core.Node) error {
_ = node

func(_ *core.Node) error {
return nil
},
pref.WithSubscription(enums.SubscribeFiles),
pref.WithContext(ctx),
).Navigate()
Expect(err).To(Succeed())
})
Expand All @@ -87,17 +82,14 @@ var _ = Describe("Traverse", func() {
defer leaktest.Check(GinkgoT())()

ctx, cancel := context.WithCancel(context.Background())
_, err := traverse.Run(
pref.WithContext(ctx),
pref.WithCancel(cancel),
).Primary(
_, err := traverse.Run().Primary(
"/root-path",
func(node *core.Node) error {
_ = node

func(_ *core.Node) error {
return nil
},
pref.WithSubscription(enums.SubscribeFiles),
pref.WithContext(ctx),
pref.WithCancel(cancel),
).Navigate()
Expect(err).To(Succeed())
})
Expand All @@ -107,10 +99,10 @@ var _ = Describe("Traverse", func() {
It("should: run primary navigation successfully", func() {
defer leaktest.Check(GinkgoT())()

ctx := context.Background()
_, err := traverse.Run(
pref.WithContext(ctx),
).Resume(
// for resume, the context should be set in the
// restore function
//
_, err := traverse.Run().Resume(
"/from-restore-path",
).Navigate()
Expect(err).To(Succeed())
Expand Down

0 comments on commit f2e0a7b

Please sign in to comment.