MCPcopy Create free account
hub / github.com/CPChain/chain / SomeSubscription

Method SomeSubscription

api/rpc/subscription_test.go:53–88  ·  view source on GitHub ↗
(ctx context.Context, n, val int)

Source from the content-addressed store, hash-verified

51}
52
53func (s *NotificationTestService) SomeSubscription(ctx context.Context, n, val int) (*Subscription, error) {
54 notifier, supported := NotifierFromContext(ctx)
55 if !supported {
56 return nil, ErrNotificationsUnsupported
57 }
58
59 // by explicitly creating an subscription we make sure that the subscription id is send back to the client
60 // before the first subscription.Notify is called. Otherwise the events might be send before the response
61 // for the eth_subscribe method.
62 subscription := notifier.CreateSubscription()
63
64 go func() {
65 // test expects n events, if we begin sending event immediately some events
66 // will probably be dropped since the subscription ID might not be send to
67 // the client.
68 time.Sleep(5 * time.Second)
69 for i := 0; i < n; i++ {
70 if err := notifier.Notify(subscription.ID, val+i); err != nil {
71 return
72 }
73 }
74
75 select {
76 case <-notifier.Closed():
77 s.mu.Lock()
78 s.unsubscribed = true
79 s.mu.Unlock()
80 case <-subscription.Err():
81 s.mu.Lock()
82 s.unsubscribed = true
83 s.mu.Unlock()
84 }
85 }()
86
87 return subscription, nil
88}
89
90// HangSubscription blocks on s.unblockHangSubscription before
91// sending anything.

Callers

nothing calls this directly

Calls 8

NotifierFromContextFunction · 0.85
CreateSubscriptionMethod · 0.80
SleepMethod · 0.80
LockMethod · 0.80
UnlockMethod · 0.80
ClosedMethod · 0.65
ErrMethod · 0.65
NotifyMethod · 0.45

Tested by

no test coverage detected