()
| 39 | } |
| 40 | |
| 41 | func ExampleClientSubscription() { |
| 42 | // Connect the client. |
| 43 | client, _ := rpc.Dial("ws://127.0.0.1:8485") |
| 44 | subch := make(chan Block) |
| 45 | |
| 46 | // Ensure that subch receives the latest block. |
| 47 | go func() { |
| 48 | for i := 0; ; i++ { |
| 49 | if i > 0 { |
| 50 | time.Sleep(2 * time.Second) |
| 51 | } |
| 52 | subscribeBlocks(client, subch) |
| 53 | } |
| 54 | }() |
| 55 | |
| 56 | // Print events from the subscription as they arrive. |
| 57 | for block := range subch { |
| 58 | fmt.Println("latest block:", block.Number) |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | // subscribeBlocks runs in its own goroutine and maintains |
| 63 | // a subscription for new blocks. |
nothing calls this directly
no test coverage detected