File: channels_test.go

package info (click to toggle)
golang-bugst-f 0.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 108 kB
  • sloc: makefile: 2
file content (41 lines) | stat: -rw-r--r-- 807 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// This file is part of go-algorithms.
//
// Copyright 2024 Cristian Maglie. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//

package f_test

import (
	"testing"
	"time"

	"github.com/stretchr/testify/require"
	f "go.bug.st/f"
)

func TestFutures(t *testing.T) {
	{
		var futureInt f.Future[int]
		go func() {
			time.Sleep(100 * time.Millisecond)
			futureInt.Send(5)
		}()
		require.Equal(t, 5, futureInt.Await())
		go func() {
			require.Equal(t, 5, futureInt.Await())
		}()
		go func() {
			require.Equal(t, 5, futureInt.Await())
		}()
	}
	{
		var futureInt f.Future[int]
		futureInt.Send(5)
		require.Equal(t, 5, futureInt.Await())
		require.Equal(t, 5, futureInt.Await())
		require.Equal(t, 5, futureInt.Await())
	}
}